llvm运行万花筒示例

时间:2019-05-02 18:30:59

标签: llvm kaleidoscope

我正在使用mac osX。我从git repo下载了llvm,现在我试图构建示例(第6章)。我安装了llvm: 运行时:which llvm-config 我得到/usr/local/bin/llvm-config

运行时

clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core mcjit native` -O3 -o toy

如以下建议:http://llvm.org/docs/tutorial/LangImpl06.html

我明白了:

Undefined symbols for architecture x86_64:
  "llvm::orc::SimpleCompiler::operator()(llvm::Module&)", referenced from:
      llvm::orc::LegacyIRCompileLayer<llvm::orc::LegacyRTDyldObjectLinkingLayer, llvm::orc::SimpleCompiler>::addModule(unsigned long long, std::__1::unique_ptr<llvm::Module, std::__1::default_delete<llvm::Module> >) in toy-e99926.o
  "llvm::orc::SymbolResolver::anchor()", referenced from:
      vtable for llvm::orc::LegacyLookupFnResolver<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)> in toy-e99926.o
  "llvm::orc::SymbolStringPtr::Tombstone", referenced from:
      llvm::orc::JITDylib::~JITDylib() in toy-e99926.o
      llvm::orc::JITDylib::MaterializingInfo::~MaterializingInfo() in toy-e99926.o
      llvm::orc::LegacyLookupFnResolver<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>::getResponsibilitySet(llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&) in toy-e99926.o
      llvm::orc::getResponsibilitySetWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>(llvm::Expected<llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > >, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)) in toy-e99926.o
      std::__1::pair<llvm::DenseMapIterator<llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr>, false>, bool> llvm::DenseMapBase<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr> >, llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr> >::try_emplace<llvm::detail::DenseSetEmpty&>(llvm::orc::SymbolStringPtr const&, llvm::detail::DenseSetEmpty&&&) in toy-e99926.o
      llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr>* llvm::DenseMapBase<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr> >, llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr> >::InsertIntoBucketImpl<llvm::orc::SymbolStringPtr>(llvm::orc::SymbolStringPtr const&, llvm::orc::SymbolStringPtr const&, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr>*) in toy-e99926.o
      llvm::DenseMapBase<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr> >, llvm::orc::SymbolStringPtr, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr> >::moveFromOldBuckets(llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr>*, llvm::detail::DenseSetPair<llvm::orc::SymbolStringPtr>*) in toy-e99926.o
      ...
  "llvm::orc::ExecutionSession::legacyFailQuery(llvm::orc::AsynchronousSymbolQuery&, llvm::Error)", referenced from:
      llvm::orc::lookupWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>(llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> >, llvm::orc::ExecutionSession&, llvm::orc::AsynchronousSymbolQuery&, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)) in toy-e99926.o
  "llvm::orc::ExecutionSession::ExecutionSession(std::__1::shared_ptr<llvm::orc::SymbolStringPool>)", referenced from:
      llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT() in toy-e99926.o
  "llvm::orc::AsynchronousSymbolQuery::handleFullyReady()", referenced from:
      llvm::orc::lookupWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>(llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> >, llvm::orc::ExecutionSession&, llvm::orc::AsynchronousSymbolQuery&, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)) in toy-e99926.o
  "llvm::orc::AsynchronousSymbolQuery::notifySymbolReady()", referenced from:
      llvm::orc::lookupWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>(llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> >, llvm::orc::ExecutionSession&, llvm::orc::AsynchronousSymbolQuery&, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)) in toy-e99926.o
  "llvm::orc::AsynchronousSymbolQuery::handleFullyResolved()", referenced from:
      llvm::orc::lookupWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>(llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> >, llvm::orc::ExecutionSession&, llvm::orc::AsynchronousSymbolQuery&, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)) in toy-e99926.o
  "llvm::orc::AsynchronousSymbolQuery::resolve(llvm::orc::SymbolStringPtr const&, llvm::JITEvaluatedSymbol)", referenced from:
      llvm::orc::lookupWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>(llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> >, llvm::orc::ExecutionSession&, llvm::orc::AsynchronousSymbolQuery&, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr> > const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::'lambda'(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)) in toy-e99926.o
  "llvm::orc::JITSymbolResolverAdapter::JITSymbolResolverAdapter(llvm::orc::ExecutionSession&, llvm::orc::SymbolResolver&, llvm::orc::MaterializationResponsibility*)", referenced from:
      llvm::orc::LegacyRTDyldObjectLinkingLayer::ConcreteLinkedObject<std::__1::shared_ptr<llvm::RuntimeDyld::MemoryManager> >::finalize() in toy-e99926.o
  "vtable for llvm::orc::JITSymbolResolverAdapter", referenced from:
      llvm::orc::LegacyRTDyldObjectLinkingLayer::ConcreteLinkedObject<std::__1::shared_ptr<llvm::RuntimeDyld::MemoryManager> >::finalize() in toy-e99926.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人知道如何解决吗?

2 个答案:

答案 0 :(得分:0)

像这样运行:

clang++ -g toy.cpp $(llvm-config --cxxflags --ldflags --system-libs --libs) -O3 -o toy

似乎可以正常使用

我确认您需要做的就是按照快速入门部分中的步骤http://llvm.org/docs/CMake.html,然后按照我上面介绍的方式运行命令,至少在第6章中可以使用

答案 1 :(得分:0)

奖金

用于Clion MacOs X和linux(未测试linux)的Cmake文件可能看起来像这样。 确保正确安装了llvm(按照上述步骤操作)

cmake_minimum_required(VERSION 3.10)
project(project_name )

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

link_libraries()
execute_process(COMMAND llvm-config --libs OUTPUT_VARIABLE LIBS)
execute_process(COMMAND llvm-config --system-libs OUTPUT_VARIABLE SYS_LIBS)
execute_process(COMMAND llvm-config --ldflags OUTPUT_VARIABLE LDF)
#message(STATUS "Found LLVM" ${LIBS})

string(STRIP ${LIBS} LIBS)
string(STRIP ${SYS_LIBS} SYS_LIBS)
string(STRIP ${LDF} LDF)

link_libraries(${LIBS} ${SYS_LIBS} ${LDF})

execute_process(COMMAND llvm-config --cxxflags OUTPUT_VARIABLE CMAKE_CXX_FLAGS)
string(STRIP ${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)

add_executable(project_name   toy.cpp)