不能 link 对抗自建的 LLVM API
Can't link against self built LLVM API
我需要 LLVM API(版本 13)的最新存储库中的一项功能,因此我克隆了存储库并构建了它们以代替旧系统安装的 LLVM 文件(版本 12)使用。出于某种原因,虽然在传递由克隆的 repo 构建的 llvm-config
实例提供的必要标志时,GCC 或 Clang 都不能 link 任何 LLVM API 函数,让每个函数都来在 linking 阶段作为未定义的参考。这是我的命令 运行:
gcc -I. $(llvm-config --cflags) $(llvm-config --ldflags) $(llvm-config --libs all) code.c
其中 llvm-config
已针对最新 repo 中生成的二进制文件进行了 symlinked。如果我切换回 linking 旧系统文件,上面的命令工作得很好。
有什么方法可以让我错误地配置 LLVM 存储库的构建,或者版本 12 和 13 之间的更改可能会妨碍?如有任何建议,我们将不胜感激。
编辑:
将 code.c
参数移动到命令的开头时,我收到更多未定义的引用错误,这是前 20 个:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `llvm::X86AsmPrinter::emitEndOfAsmFile(llvm::Module&)':
X86AsmPrinter.cpp:(.text._ZN4llvm13X86AsmPrinter16emitEndOfAsmFileERNS_6ModuleE+0x259): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZN4llvm13X86AsmPrinter16emitEndOfAsmFileERNS_6ModuleE+0x336): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `llvm::RegisterAsmPrinter<llvm::X86AsmPrinter>::Allocator(llvm::TargetMachine&, std::unique_ptr<llvm::MCStreamer, std::default_delete<llvm::MCStreamer> >&&)':
X86AsmPrinter.cpp:(.text._ZN4llvm18RegisterAsmPrinterINS_13X86AsmPrinterEE9AllocatorERNS_13TargetMachineEOSt10unique_ptrINS_10MCStreamerESt14default_deleteIS6_EE[_ZN4llvm18RegisterAsmPrinterINS_13X86AsmPrinterEE9AllocatorERNS_13TargetMachineEOSt10unique_ptrINS_10MCStreamerESt14default_deleteIS6_EE]+0x2b): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `llvm::X86AsmPrinter::PrintSymbolOperand(llvm::MachineOperand const&, llvm::raw_ostream&)':
X86AsmPrinter.cpp:(.text._ZN4llvm13X86AsmPrinter18PrintSymbolOperandERKNS_14MachineOperandERNS_11raw_ostreamE+0x7c0): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `std::_Rb_tree<llvm::MCSymbol const*, std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > >, std::_Select1st<std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > > >, llvm::FaultMaps::MCSymbolComparator, std::allocator<std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > > > >::_M_erase(std::_Rb_tree_node<std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > > >*)':
X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0xcc): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0xde): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x104): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x111): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x139): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o):X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x157): more undefined references to `operator delete(void*, unsigned long)' follow
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86MCInstLower.cpp.o): in function `(anonymous namespace)::X86MCInstLower::GetSymbolFromOperand(llvm::MachineOperand const&) const':
X86MCInstLower.cpp:(.text._ZNK12_GLOBAL__N_114X86MCInstLower20GetSymbolFromOperandERKN4llvm14MachineOperandE+0x4ee): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86MCInstLower.cpp:(.text._ZNK12_GLOBAL__N_114X86MCInstLower20GetSymbolFromOperandERKN4llvm14MachineOperandE+0x5f6): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86MCInstLower.cpp.o): in function `llvm::APFloat::Storage::~Storage()':
X86MCInstLower.cpp:(.text._ZN4llvm7APFloat7StorageD2Ev[_ZN4llvm7APFloat7StorageD5Ev]+0x1bb): undefined reference to `operator delete[](void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86MCInstLower.cpp:(.text._ZN4llvm7APFloat7StorageD2Ev[_ZN4llvm7APFloat7StorageD5Ev]+0x1d7): undefined reference to `operator delete[](void*, unsigned long)'
这里是 llvm-config --cflags --ldflags --libs all
的确切输出:
-I/home/muke/Programming/Project/llvm-project/llvm/include -I/home/muke/Programming/Project/llvm-project/build/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/home/muke/Programming/Project/llvm-project/build/lib -lLLVMWindowsManifest -lLLVMXRay -lLLVMLibDriver -lLLVMDlltoolDriver -lLLVMCoverage -lLLVMLineEditor -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyUtils -lLLVMWebAssemblyInfo -lLLVMSystemZDisassembler -lLLVMSystemZAsmParser -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSparcDisassembler -lLLVMSparcAsmParser -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMRISCVDisassembler -lLLVMRISCVAsmParser -lLLVMRISCVCodeGen -lLLVMRISCVDesc -lLLVMRISCVInfo -lLLVMPowerPCDisassembler -lLLVMPowerPCAsmParser -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMMSP430Disassembler -lLLVMMSP430AsmParser -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMipsDisassembler -lLLVMMipsAsmParser -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFAsmParser -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMAVRDisassembler -lLLVMAVRAsmParser -lLLVMAVRCodeGen -lLLVMAVRDesc -lLLVMAVRInfo -lLLVMARMDisassembler -lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMAMDGPUDisassembler -lLLVMAMDGPUAsmParser -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMDGPUInfo -lLLVMAArch64Disassembler -lLLVMAArch64AsmParser -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMOrcJIT -lLLVMMCJIT -lLLVMJITLink -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoGSYM -lLLVMOption -lLLVMObjectYAML -lLLVMMCA -lLLVMMCDisassembler -lLLVMLTO -lLLVMPasses -lLLVMCFGuard -lLLVMCoroutines -lLLVMObjCARCOpts -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMInstrumentation -lLLVMFrontendOpenMP -lLLVMFrontendOpenACC -lLLVMExtensions -lLLVMDWARFLinker -lLLVMGlobalISel -lLLVMMIRParser -lLLVMAsmPrinter -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMSelectionDAG -lLLVMCodeGen -lLLVMIRReader -lLLVMAsmParser -lLLVMInterfaceStub -lLLVMFileCheck -lLLVMFuzzMutate -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMBitReader -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTableGen -lLLVMSupport -lLLVMDemangle
尝试编译和 linking g++
给出了一组新的未定义引用:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::llvm_execute_on_thread_impl(void* (*)(void*), void*, llvm::Optional<unsigned int>)':
Threading.cpp:(.text._ZN4llvm27llvm_execute_on_thread_implEPFPvS0_ES0_NS_8OptionalIjEE+0x4e): undefined reference to `pthread_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Threading.cpp:(.text._ZN4llvm27llvm_execute_on_thread_implEPFPvS0_ES0_NS_8OptionalIjEE+0x8e): undefined reference to `pthread_attr_setstacksize'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::llvm_thread_detach_impl(unsigned long)':
Threading.cpp:(.text._ZN4llvm23llvm_thread_detach_implEm+0x5): undefined reference to `pthread_detach'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::llvm_thread_join_impl(unsigned long)':
Threading.cpp:(.text._ZN4llvm21llvm_thread_join_implEm+0x7): undefined reference to `pthread_join'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::set_thread_name(llvm::Twine const&)':
Threading.cpp:(.text._ZN4llvm15set_thread_nameERKNS_5TwineE+0x4d): undefined reference to `pthread_setname_np'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::get_thread_name(llvm::SmallVectorImpl<char>&)':
Threading.cpp:(.text._ZN4llvm15get_thread_nameERNS_15SmallVectorImplIcEE+0x3f): undefined reference to `pthread_getname_np'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl<char>&, int)':
Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x2f): undefined reference to `compressBound'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x50): undefined reference to `compress2'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::uncompress(llvm::StringRef, char*, unsigned long&)':
Compression.cpp:(.text._ZN4llvm4zlib10uncompressENS_9StringRefEPcRm+0x2d): undefined reference to `uncompress'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::uncompress(llvm::StringRef, llvm::SmallVectorImpl<char>&, unsigned long)':
Compression.cpp:(.text._ZN4llvm4zlib10uncompressENS_9StringRefERNS_15SmallVectorImplIcEEm+0x42): undefined reference to `uncompress'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::crc32(llvm::StringRef)':
Compression.cpp:(.text._ZN4llvm4zlib5crc32ENS_9StringRefE+0xd): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(CRC.cpp.o): in function `llvm::crc32(unsigned int, llvm::ArrayRef<unsigned char>)':
CRC.cpp:(.text._ZN4llvm5crc32EjNS_8ArrayRefIhEE+0x35): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(CRC.cpp.o): in function `llvm::crc32(llvm::ArrayRef<unsigned char>)':
CRC.cpp:(.text._ZN4llvm5crc32ENS_8ArrayRefIhEE+0x35): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(CRC.cpp.o): in function `llvm::JamCRC::update(llvm::ArrayRef<unsigned char>)':
CRC.cpp:(.text._ZN4llvm6JamCRC6updateENS_8ArrayRefIhEE+0x36): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::object_deleter<llvm::sys::DynamicLibrary::HandleSet>::call(void*)':
DynamicLibrary.cpp:(.text._ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv[_ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv]+0x29): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv[_ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv]+0x3c): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::~HandleSet()':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSetD2Ev+0x21): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSetD2Ev+0x35): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::DLOpen(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet6DLOpenEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x10): undefined reference to `dlopen'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet6DLOpenEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2e): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::DLClose(void*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet7DLCloseEPv+0x1): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::DLSym(void*, char const*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet5DLSymEPvPKc+0x1): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::getAddressOfSymbol(char const*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary18getAddressOfSymbolEPKc+0xd): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(char const*) [clone .localalias]':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x157): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x284): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x2c7): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o):DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x3a8): more undefined references to `dlsym' follow
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::getPermanentLibrary(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) [clone .localalias]':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x3e): undefined reference to `dlopen'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xfd): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x1e2): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2ba): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Process.cpp.o): in function `llvm::sys::Process::FileDescriptorHasColors(int) [clone .part.0]':
Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0x50): undefined reference to `set_curterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0x69): undefined reference to `setupterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0xa8): undefined reference to `tigetnum'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0xb2): undefined reference to `set_curterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0xba): undefined reference to `del_curterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl() [clone .localalias]':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImplD2Ev+0x12): undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl() [clone .localalias]':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImplD0Ev+0x16): undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::ThreadLocalImpl()':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImplC2Ev+0x20): undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::setInstance(void const*)':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImpl11setInstanceEPKv+0x4): undefined reference to `pthread_setspecific'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::getInstance()':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImpl11getInstanceEv+0x4): undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::removeInstance()':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImpl14removeInstanceEv+0x6): undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
以热门评论开头...
啊哈! llvm/clang
是用 C++ 编写的,不是 C.
link 抱怨 [除其他外] 无法解决:
operator new(unsigned long)
这是 c++ 编译器 [来自内部库] 提供的标准函数。它不是来自 LLVM 库。
未解决,因为您 linking 与 gcc
.
Relink 与 g++
[或 c++
](例如:
cfg=llvm-config-<ver>
gcc -I. $($cfg --cflags) -c code.c
g++ -o code code.o $($cfg --ldflags --libs)
这可能就足够了。
否则,您可能需要将 code.c
重命名为 code.cpp
(即 您的 程序可能必须是 C++ 代码)并使用 g++
还有:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs)
更新:
Both suggestions here lead to the same set of new undefined reference errors that I've edited into the OP. – muke
这 确实 修复了 C++ 与 C 的问题。
还有一些其他符号未解析:
compress2 compressBound crc32 del_curterm dlclose dlerror dlopen
dlsym pthread_attr_setstacksize pthread_create pthread_detach
pthread_getname_np pthread_getspecific pthread_join pthread_key_create
pthread_key_delete pthread_setname_np pthread_setspecific set_curterm
setupterm tigetnum uncompress
该代码是多线程的并使用 pthreads
,需要库来解析各种 pthread_*
符号。因此,将 -lpthread
添加到 link 命令的 end。
crc32
等。阿尔。由 zlib
提供,因此您可能还需要 -lz
.
此外,dlopen
等。阿尔。由 -ldl
(动态 linking 库)提供。
还有,set_curterm
等。阿尔。由 curses 库提供,所以我们可能需要 -lcurses
[或 -lncurses
代替]
所以,我会尝试:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs) -lz -lpthread -lcurses -ldl
如果这不起作用,您可能需要调整这些 -l*
选项的顺序,但按原样试一试。
或者,作为替代 [作为最后的手段],您可以将它们放在 linker 组中:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs) \
-Wl,--start-group -lz -lpthread -lcurses -ldl -Wl,--end-group
但是,linker 组 [通常] 对 .a
文件比 .so
文件更有帮助。
更新#2:
Thanks for the edit, this was resolved most of the symbols. The last one is 'del_curterm', do you know which library provides this?
这是 -lncurses
中的一个外部对象。查看此内容的方法是查看以下输出:readelf -a /usr/lib64/libncurses.so.6
There's one more error after this too: /lib64/libtinfo.so.6: error adding symbols: DSO missing from command line, I'm not sure what this means though. – muke
如果你这样做:ldd /usr/lib64/libncurses.6.so
,它会告诉它需要哪些[共享]库。其中之一是 [惊喜 ;-)]:/lib64/libtinfo.so.6
关于 DSO 问题,google 在 phrase/sentence 上的搜索:DSO missing from command line
,产生[除其他外] link 至:
libpthread.so.0: error adding symbols: DSO missing from command line
从那个页面来看,问题类似于您原来的问题 not puting the --libs
argument as the last linking.
时的参数
该页面的解决方案之一是使用我之前提到的 linker 组(例如)将 -l*
选项包装在 [aformentioned] -Wl,*
选项中:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs) \
-Wl,--start-group -lz -lpthread -lcurses -ltinfo -ldl -Wl,--end-group
我需要 LLVM API(版本 13)的最新存储库中的一项功能,因此我克隆了存储库并构建了它们以代替旧系统安装的 LLVM 文件(版本 12)使用。出于某种原因,虽然在传递由克隆的 repo 构建的 llvm-config
实例提供的必要标志时,GCC 或 Clang 都不能 link 任何 LLVM API 函数,让每个函数都来在 linking 阶段作为未定义的参考。这是我的命令 运行:
gcc -I. $(llvm-config --cflags) $(llvm-config --ldflags) $(llvm-config --libs all) code.c
其中 llvm-config
已针对最新 repo 中生成的二进制文件进行了 symlinked。如果我切换回 linking 旧系统文件,上面的命令工作得很好。
有什么方法可以让我错误地配置 LLVM 存储库的构建,或者版本 12 和 13 之间的更改可能会妨碍?如有任何建议,我们将不胜感激。
编辑:
将 code.c
参数移动到命令的开头时,我收到更多未定义的引用错误,这是前 20 个:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `llvm::X86AsmPrinter::emitEndOfAsmFile(llvm::Module&)':
X86AsmPrinter.cpp:(.text._ZN4llvm13X86AsmPrinter16emitEndOfAsmFileERNS_6ModuleE+0x259): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZN4llvm13X86AsmPrinter16emitEndOfAsmFileERNS_6ModuleE+0x336): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `llvm::RegisterAsmPrinter<llvm::X86AsmPrinter>::Allocator(llvm::TargetMachine&, std::unique_ptr<llvm::MCStreamer, std::default_delete<llvm::MCStreamer> >&&)':
X86AsmPrinter.cpp:(.text._ZN4llvm18RegisterAsmPrinterINS_13X86AsmPrinterEE9AllocatorERNS_13TargetMachineEOSt10unique_ptrINS_10MCStreamerESt14default_deleteIS6_EE[_ZN4llvm18RegisterAsmPrinterINS_13X86AsmPrinterEE9AllocatorERNS_13TargetMachineEOSt10unique_ptrINS_10MCStreamerESt14default_deleteIS6_EE]+0x2b): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `llvm::X86AsmPrinter::PrintSymbolOperand(llvm::MachineOperand const&, llvm::raw_ostream&)':
X86AsmPrinter.cpp:(.text._ZN4llvm13X86AsmPrinter18PrintSymbolOperandERKNS_14MachineOperandERNS_11raw_ostreamE+0x7c0): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o): in function `std::_Rb_tree<llvm::MCSymbol const*, std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > >, std::_Select1st<std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > > >, llvm::FaultMaps::MCSymbolComparator, std::allocator<std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > > > >::_M_erase(std::_Rb_tree_node<std::pair<llvm::MCSymbol const* const, std::vector<llvm::FaultMaps::FaultInfo, std::allocator<llvm::FaultMaps::FaultInfo> > > >*)':
X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0xcc): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0xde): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x104): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x111): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x139): undefined reference to `operator delete(void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86AsmPrinter.cpp.o):X86AsmPrinter.cpp:(.text._ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E[_ZNSt8_Rb_treeIPKN4llvm8MCSymbolESt4pairIKS3_St6vectorINS0_9FaultMaps9FaultInfoESaIS8_EEESt10_Select1stISB_ENS7_18MCSymbolComparatorESaISB_EE8_M_eraseEPSt13_Rb_tree_nodeISB_E]+0x157): more undefined references to `operator delete(void*, unsigned long)' follow
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86MCInstLower.cpp.o): in function `(anonymous namespace)::X86MCInstLower::GetSymbolFromOperand(llvm::MachineOperand const&) const':
X86MCInstLower.cpp:(.text._ZNK12_GLOBAL__N_114X86MCInstLower20GetSymbolFromOperandERKN4llvm14MachineOperandE+0x4ee): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86MCInstLower.cpp:(.text._ZNK12_GLOBAL__N_114X86MCInstLower20GetSymbolFromOperandERKN4llvm14MachineOperandE+0x5f6): undefined reference to `operator new(unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMX86CodeGen.a(X86MCInstLower.cpp.o): in function `llvm::APFloat::Storage::~Storage()':
X86MCInstLower.cpp:(.text._ZN4llvm7APFloat7StorageD2Ev[_ZN4llvm7APFloat7StorageD5Ev]+0x1bb): undefined reference to `operator delete[](void*, unsigned long)'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: X86MCInstLower.cpp:(.text._ZN4llvm7APFloat7StorageD2Ev[_ZN4llvm7APFloat7StorageD5Ev]+0x1d7): undefined reference to `operator delete[](void*, unsigned long)'
这里是 llvm-config --cflags --ldflags --libs all
的确切输出:
-I/home/muke/Programming/Project/llvm-project/llvm/include -I/home/muke/Programming/Project/llvm-project/build/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/home/muke/Programming/Project/llvm-project/build/lib -lLLVMWindowsManifest -lLLVMXRay -lLLVMLibDriver -lLLVMDlltoolDriver -lLLVMCoverage -lLLVMLineEditor -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMWebAssemblyDisassembler -lLLVMWebAssemblyAsmParser -lLLVMWebAssemblyCodeGen -lLLVMWebAssemblyDesc -lLLVMWebAssemblyUtils -lLLVMWebAssemblyInfo -lLLVMSystemZDisassembler -lLLVMSystemZAsmParser -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSparcDisassembler -lLLVMSparcAsmParser -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMRISCVDisassembler -lLLVMRISCVAsmParser -lLLVMRISCVCodeGen -lLLVMRISCVDesc -lLLVMRISCVInfo -lLLVMPowerPCDisassembler -lLLVMPowerPCAsmParser -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMMSP430Disassembler -lLLVMMSP430AsmParser -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMipsDisassembler -lLLVMMipsAsmParser -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFAsmParser -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMAVRDisassembler -lLLVMAVRAsmParser -lLLVMAVRCodeGen -lLLVMAVRDesc -lLLVMAVRInfo -lLLVMARMDisassembler -lLLVMARMAsmParser -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMUtils -lLLVMARMInfo -lLLVMAMDGPUDisassembler -lLLVMAMDGPUAsmParser -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMDGPUInfo -lLLVMAArch64Disassembler -lLLVMAArch64AsmParser -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Utils -lLLVMAArch64Info -lLLVMOrcJIT -lLLVMMCJIT -lLLVMJITLink -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMOrcTargetProcess -lLLVMOrcShared -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoGSYM -lLLVMOption -lLLVMObjectYAML -lLLVMMCA -lLLVMMCDisassembler -lLLVMLTO -lLLVMPasses -lLLVMCFGuard -lLLVMCoroutines -lLLVMObjCARCOpts -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMInstrumentation -lLLVMFrontendOpenMP -lLLVMFrontendOpenACC -lLLVMExtensions -lLLVMDWARFLinker -lLLVMGlobalISel -lLLVMMIRParser -lLLVMAsmPrinter -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMSelectionDAG -lLLVMCodeGen -lLLVMIRReader -lLLVMAsmParser -lLLVMInterfaceStub -lLLVMFileCheck -lLLVMFuzzMutate -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMBitReader -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMTableGen -lLLVMSupport -lLLVMDemangle
尝试编译和 linking g++
给出了一组新的未定义引用:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::llvm_execute_on_thread_impl(void* (*)(void*), void*, llvm::Optional<unsigned int>)':
Threading.cpp:(.text._ZN4llvm27llvm_execute_on_thread_implEPFPvS0_ES0_NS_8OptionalIjEE+0x4e): undefined reference to `pthread_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Threading.cpp:(.text._ZN4llvm27llvm_execute_on_thread_implEPFPvS0_ES0_NS_8OptionalIjEE+0x8e): undefined reference to `pthread_attr_setstacksize'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::llvm_thread_detach_impl(unsigned long)':
Threading.cpp:(.text._ZN4llvm23llvm_thread_detach_implEm+0x5): undefined reference to `pthread_detach'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::llvm_thread_join_impl(unsigned long)':
Threading.cpp:(.text._ZN4llvm21llvm_thread_join_implEm+0x7): undefined reference to `pthread_join'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::set_thread_name(llvm::Twine const&)':
Threading.cpp:(.text._ZN4llvm15set_thread_nameERKNS_5TwineE+0x4d): undefined reference to `pthread_setname_np'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Threading.cpp.o): in function `llvm::get_thread_name(llvm::SmallVectorImpl<char>&)':
Threading.cpp:(.text._ZN4llvm15get_thread_nameERNS_15SmallVectorImplIcEE+0x3f): undefined reference to `pthread_getname_np'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl<char>&, int)':
Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x2f): undefined reference to `compressBound'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x50): undefined reference to `compress2'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::uncompress(llvm::StringRef, char*, unsigned long&)':
Compression.cpp:(.text._ZN4llvm4zlib10uncompressENS_9StringRefEPcRm+0x2d): undefined reference to `uncompress'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::uncompress(llvm::StringRef, llvm::SmallVectorImpl<char>&, unsigned long)':
Compression.cpp:(.text._ZN4llvm4zlib10uncompressENS_9StringRefERNS_15SmallVectorImplIcEEm+0x42): undefined reference to `uncompress'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Compression.cpp.o): in function `llvm::zlib::crc32(llvm::StringRef)':
Compression.cpp:(.text._ZN4llvm4zlib5crc32ENS_9StringRefE+0xd): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(CRC.cpp.o): in function `llvm::crc32(unsigned int, llvm::ArrayRef<unsigned char>)':
CRC.cpp:(.text._ZN4llvm5crc32EjNS_8ArrayRefIhEE+0x35): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(CRC.cpp.o): in function `llvm::crc32(llvm::ArrayRef<unsigned char>)':
CRC.cpp:(.text._ZN4llvm5crc32ENS_8ArrayRefIhEE+0x35): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(CRC.cpp.o): in function `llvm::JamCRC::update(llvm::ArrayRef<unsigned char>)':
CRC.cpp:(.text._ZN4llvm6JamCRC6updateENS_8ArrayRefIhEE+0x36): undefined reference to `crc32'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::object_deleter<llvm::sys::DynamicLibrary::HandleSet>::call(void*)':
DynamicLibrary.cpp:(.text._ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv[_ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv]+0x29): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv[_ZN4llvm14object_deleterINS_3sys14DynamicLibrary9HandleSetEE4callEPv]+0x3c): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::~HandleSet()':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSetD2Ev+0x21): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSetD2Ev+0x35): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::DLOpen(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet6DLOpenEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x10): undefined reference to `dlopen'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet6DLOpenEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2e): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::DLClose(void*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet7DLCloseEPv+0x1): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::HandleSet::DLSym(void*, char const*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary9HandleSet5DLSymEPvPKc+0x1): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::getAddressOfSymbol(char const*)':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary18getAddressOfSymbolEPKc+0xd): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(char const*) [clone .localalias]':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x157): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x284): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x2c7): undefined reference to `dlsym'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o):DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary24SearchForAddressOfSymbolEPKc+0x3a8): more undefined references to `dlsym' follow
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): in function `llvm::sys::DynamicLibrary::getPermanentLibrary(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) [clone .localalias]':
DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x3e): undefined reference to `dlopen'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xfd): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x1e2): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: DynamicLibrary.cpp:(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2ba): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(Process.cpp.o): in function `llvm::sys::Process::FileDescriptorHasColors(int) [clone .part.0]':
Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0x50): undefined reference to `set_curterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0x69): undefined reference to `setupterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0xa8): undefined reference to `tigetnum'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0xb2): undefined reference to `set_curterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi.part.0+0xba): undefined reference to `del_curterm'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl() [clone .localalias]':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImplD2Ev+0x12): undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::~ThreadLocalImpl() [clone .localalias]':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImplD0Ev+0x16): undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::ThreadLocalImpl()':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImplC2Ev+0x20): undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::setInstance(void const*)':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImpl11setInstanceEPKv+0x4): undefined reference to `pthread_setspecific'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::getInstance()':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImpl11getInstanceEv+0x4): undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/muke/Programming/Project/llvm-project/build/lib/libLLVMSupport.a(ThreadLocal.cpp.o): in function `llvm::sys::ThreadLocalImpl::removeInstance()':
ThreadLocal.cpp:(.text._ZN4llvm3sys15ThreadLocalImpl14removeInstanceEv+0x6): undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
以热门评论开头...
啊哈! llvm/clang
是用 C++ 编写的,不是 C.
link 抱怨 [除其他外] 无法解决:
operator new(unsigned long)
这是 c++ 编译器 [来自内部库] 提供的标准函数。它不是来自 LLVM 库。
未解决,因为您 linking 与 gcc
.
Relink 与 g++
[或 c++
](例如:
cfg=llvm-config-<ver>
gcc -I. $($cfg --cflags) -c code.c
g++ -o code code.o $($cfg --ldflags --libs)
这可能就足够了。
否则,您可能需要将 code.c
重命名为 code.cpp
(即 您的 程序可能必须是 C++ 代码)并使用 g++
还有:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs)
更新:
Both suggestions here lead to the same set of new undefined reference errors that I've edited into the OP. – muke
这 确实 修复了 C++ 与 C 的问题。
还有一些其他符号未解析:
compress2 compressBound crc32 del_curterm dlclose dlerror dlopen
dlsym pthread_attr_setstacksize pthread_create pthread_detach
pthread_getname_np pthread_getspecific pthread_join pthread_key_create
pthread_key_delete pthread_setname_np pthread_setspecific set_curterm
setupterm tigetnum uncompress
该代码是多线程的并使用 pthreads
,需要库来解析各种 pthread_*
符号。因此,将 -lpthread
添加到 link 命令的 end。
crc32
等。阿尔。由 zlib
提供,因此您可能还需要 -lz
.
此外,dlopen
等。阿尔。由 -ldl
(动态 linking 库)提供。
还有,set_curterm
等。阿尔。由 curses 库提供,所以我们可能需要 -lcurses
[或 -lncurses
代替]
所以,我会尝试:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs) -lz -lpthread -lcurses -ldl
如果这不起作用,您可能需要调整这些 -l*
选项的顺序,但按原样试一试。
或者,作为替代 [作为最后的手段],您可以将它们放在 linker 组中:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs) \
-Wl,--start-group -lz -lpthread -lcurses -ldl -Wl,--end-group
但是,linker 组 [通常] 对 .a
文件比 .so
文件更有帮助。
更新#2:
Thanks for the edit, this was resolved most of the symbols. The last one is 'del_curterm', do you know which library provides this?
这是 -lncurses
中的一个外部对象。查看此内容的方法是查看以下输出:readelf -a /usr/lib64/libncurses.so.6
There's one more error after this too: /lib64/libtinfo.so.6: error adding symbols: DSO missing from command line, I'm not sure what this means though. – muke
如果你这样做:ldd /usr/lib64/libncurses.6.so
,它会告诉它需要哪些[共享]库。其中之一是 [惊喜 ;-)]:/lib64/libtinfo.so.6
关于 DSO 问题,google 在 phrase/sentence 上的搜索:DSO missing from command line
,产生[除其他外] link 至:
libpthread.so.0: error adding symbols: DSO missing from command line
从那个页面来看,问题类似于您原来的问题 not puting the --libs
argument as the last linking.
该页面的解决方案之一是使用我之前提到的 linker 组(例如)将 -l*
选项包装在 [aformentioned] -Wl,*
选项中:
cfg=llvm-config-<ver>
g++ -I. $($cfg --cflags) -c code.cpp
g++ -o code code.o $($cfg --ldflags --libs) \
-Wl,--start-group -lz -lpthread -lcurses -ltinfo -ldl -Wl,--end-group