我正在尝试构建llvm项目,但是ld-linker使用cmake向llvm名称空间上的每个函数返回“未定义的函数”。
我试图通过放置一些如下的cmake代码来解决此问题
set(CMAKE_EXE_LINKER_FLAGS "-I/usr/local/include -std=c++14 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/local/lib")
set(Cmake_CXX_Flags "-lLLVMXRay -lLLVMWindowsManifest -lLLVMTableGen -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMOrcJIT -lLLVMJITLink -lLLVMObjectYAML -lLLVMMCA -lLLVMLTO -lLLVMPasses -lLLVMObjCARCOpts -lLLVMLineEditor -lLLVMLibDriver -lLLVMInterpreter -lLLVMFuzzMutate -lLLVMMCJIT -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMDlltoolDriver -lLLVMOption -lLLVMDebugInfoGSYM -lLLVMCoverage -lLLVMCoroutines -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Utils -lLLVMX86Info -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyInfo -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMRISCVDisassembler -lLLVMRISCVCodeGen -lLLVMRISCVAsmParser -lLLVMRISCVDesc -lLLVMRISCVUtils -lLLVMRISCVInfo -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMMSP430Disassembler -lLLVMMSP430CodeGen -lLLVMMSP430AsmParser -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFCodeGen -lLLVMBPFAsmParser -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMAMDGPUDisassembler -lLLVMAMDGPUCodeGen -lLLVMMIRParser -lLLVMipo -lLLVMInstrumentation -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMDGPUInfo -lLLVMAArch64Disassembler -lLLVMMCDisassembler -lLLVMAArch64CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoDWARF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMTextAPI -lLLVMBitReader -lLLVMBitstreamReader -lLLVMCore -lLLVMRemarks -lLLVMAArch64AsmParser -lLLVMMCParser -lLLVMAArch64Desc -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBinaryFormat -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMSupport -lLLVMDemangle -lrt -ldl -lpthread -lm")
这些是“ llvm-config --ldflags --cxxflags”和“ llvm-config --libs --system-libs”的返回值。
命令行错误消息。
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `INT_EXPR_AST::generate()':
/home/montyaxn/work/zanka/source/ast/AST_code_gen.cpp:38: undefined reference to `llvm::APInt::APInt(unsigned int, llvm::StringRef, unsigned char)'
/usr/bin/ld: /home/montyaxn/work/zanka/source/ast/AST_code_gen.cpp:38: undefined reference to `llvm::ConstantInt::get(llvm::LLVMContext&, llvm::APInt const&)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `__cxx_global_var_init':
/home/montyaxn/work/zanka/source/ast/AST_code_gen.cpp:22: undefined reference to `llvm::LLVMContext::LLVMContext()'
/usr/bin/ld: /home/montyaxn/work/zanka/source/ast/AST_code_gen.cpp:22: undefined reference to `llvm::LLVMContext::~LLVMContext()'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::MetadataTracking::untrack(llvm::Metadata*&)':
/usr/local/include/llvm/IR/Metadata.h:245: undefined reference to `llvm::MetadataTracking::untrack(void*, llvm::Metadata&)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `std::default_delete<llvm::Module>::operator()(llvm::Module*) const':
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/unique_ptr.h:81: undefined reference to `llvm::Module::~Module()'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::ConstantFolder::CreateAdd(llvm::Constant*, llvm::Constant*, bool, bool) const':
/usr/local/include/llvm/IR/ConstantFolder.h:37: undefined reference to `llvm::ConstantExpr::getAdd(llvm::Constant*, llvm::Constant*, bool, bool)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateInsertNUWNSWBinOp(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, llvm::Twine const&, bool, bool)':
/usr/local/include/llvm/IR/IRBuilder.h:1062: undefined reference to `llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, llvm::Twine const&, llvm::Instruction*)'
/usr/bin/ld: /usr/local/include/llvm/IR/IRBuilder.h:1063: undefined reference to `llvm::Instruction::setHasNoUnsignedWrap(bool)'
/usr/bin/ld: /usr/local/include/llvm/IR/IRBuilder.h:1064: undefined reference to `llvm::Instruction::setHasNoSignedWrap(bool)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::IRBuilderDefaultInserter::InsertHelper(llvm::Instruction*, llvm::Twine const&, llvm::BasicBlock*, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>) const':
/usr/local/include/llvm/IR/IRBuilder.h:66: undefined reference to `llvm::Value::setName(llvm::Twine const&)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction>, llvm::SymbolTableListTraits<llvm::Instruction> >::insert(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>, llvm::Instruction*)':
/usr/local/include/llvm/ADT/ilist.h:227: undefined reference to `llvm::SymbolTableListTraits<llvm::Instruction>::addNodeToList(llvm::Instruction*)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::MetadataTracking::retrack(llvm::Metadata*&, llvm::Metadata*&)':
/usr/local/include/llvm/IR/Metadata.h:257: undefined reference to `llvm::MetadataTracking::retrack(void*, llvm::Metadata&, void*)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::MetadataTracking::track(llvm::Metadata*&)':
/usr/local/include/llvm/IR/Metadata.h:221: undefined reference to `llvm::MetadataTracking::track(void*, llvm::Metadata&, llvm::PointerUnion<llvm::MetadataAsValue*, llvm::Metadata*>)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::ConstantFolder::CreateSub(llvm::Constant*, llvm::Constant*, bool, bool) const':
/usr/local/include/llvm/IR/ConstantFolder.h:46: undefined reference to `llvm::ConstantExpr::getSub(llvm::Constant*, llvm::Constant*, bool, bool)'
/usr/bin/ld: CMakeFiles/giuniu.dir/source/ast/AST_code_gen.cpp.o: in function `llvm::ConstantFolder::CreateMul(llvm::Constant*, llvm::Constant*, bool, bool) const':
/usr/local/include/llvm/IR/ConstantFolder.h:55: undefined reference to `llvm::ConstantExpr::getMul(llvm::Constant*, llvm::Constant*, bool, bool)'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [CMakeFiles/giuniu.dir/build.make:174: giuniu] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/giuniu.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/giuniu.dir/rule] Error 2
make: *** [Makefile:118: giuniu] Error 2