我正在尝试按照https://llvm.org/docs/tutorial/LangImpl03.html上的步骤来构建示例。然后在Centos上运行代码。 我结束了命令:
clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy
当我包含文件llvm / ADT / APFloat.h和llvm / ADT / STLExtras.h时还可以,但是当我包含llvm / IR / BasicBlock.h等文件时,出现一些错误,如下所示:>
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `(anonymous namespace)::ErrorErrorCategory::~ErrorErrorCategory()':
Error.cpp:(.text._ZN12_GLOBAL__N_118ErrorErrorCategoryD2Ev+0xb): undefined reference to `std::_V2::error_category::~error_category()'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `(anonymous namespace)::ErrorErrorCategory::~ErrorErrorCategory()':
Error.cpp:(.text._ZN12_GLOBAL__N_118ErrorErrorCategoryD0Ev+0xf): undefined reference to `std::_V2::error_category::~error_category()'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `llvm::object_deleter<(anonymous namespace)::ErrorErrorCategory>::call(void*)':
Error.cpp:(.text._ZN4llvm14object_deleterIN12_GLOBAL__N_118ErrorErrorCategoryEE4callEPv+0x14): undefined reference to `std::_V2::error_category::~error_category()'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `llvm::ErrorInfoBase::message[abi:cxx11]() const':
Error.cpp:(.text._ZNK4llvm13ErrorInfoBase7messageB5cxx11Ev[_ZNK4llvm13ErrorInfoBase7messageB5cxx11Ev]+0x11b): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `(anonymous namespace)::ErrorErrorCategory::message(int) const':
Error.cpp:(.text._ZNK12_GLOBAL__N_118ErrorErrorCategory7messageEi+0x25): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `llvm::ECError::log(llvm::raw_ostream&) const':
Error.cpp:(.text._ZNK4llvm7ECError3logERNS_11raw_ostreamE[_ZNK4llvm7ECError3logERNS_11raw_ostreamE]+0x52): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o): In function `llvm::errorToErrorCode(llvm::Error)':
Error.cpp:(.text._ZN4llvm16errorToErrorCodeENS_5ErrorE+0x1b): undefined reference to `std::_V2::system_category()'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o):(.data.rel.ro._ZTVN12_GLOBAL__N_118ErrorErrorCategoryE+0x28): undefined reference to `std::_V2::error_category::_M_message[abi:cxx11](int) const'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o):(.data.rel.ro._ZTVN12_GLOBAL__N_118ErrorErrorCategoryE+0x38): undefined reference to `std::_V2::error_category::default_error_condition(int) const'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o):(.data.rel.ro._ZTVN12_GLOBAL__N_118ErrorErrorCategoryE+0x40): undefined reference to `std::_V2::error_category::equivalent(int, std::error_condition const&) const'
/usr/local/lib/libLLVMSupport.a(Error.cpp.o):(.data.rel.ro._ZTVN12_GLOBAL__N_118ErrorErrorCategoryE+0x48): undefined reference to `std::_V2::error_category::equivalent(std::error_code const&, int) const'
Host.cpp:(.text._ZN4llvm3sys16getProcessTripleB5cxx11Ev+0x35a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char const*, unsigned long, unsigned long) const'
Host.cpp:(.text._ZN4llvm3sys16getProcessTripleB5cxx11Ev+0x371): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::resize(unsigned long, char)'
Host.cpp:(.text._ZN4llvm3sys16getProcessTripleB5cxx11Ev+0x39e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
Host.cpp:(.text._ZN4llvm3sys16getProcessTripleB5cxx11Ev+0x3be): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/local/lib/libLLVMSupport.a(APInt.cpp.o): In function `llvm::APInt::toString[abi:cxx11](unsigned int, bool) const':
APInt.cpp:(.text._ZNK4llvm5APInt8toStringB5cxx11Ejb+0xb3): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
那么如何解决这个问题呢?谢谢。