Search code examples
cbuildllvm

Can't link against self built LLVM API


I need a feature from the latest repos for the LLVM API (version 13) so I've cloned the repo and built them to use instead of the older system installed LLVM files (version 12). For some reason though when passing the necessary flags provided by the instance of llvm-config built from the cloned repo neither GCC or Clang can link any of the LLVM API functions, having every single one come up as an undefined reference during the linking phase. Here's the command I'm running:

gcc -I. $(llvm-config --cflags) $(llvm-config --ldflags) $(llvm-config --libs all) code.c

Where llvm-config has been symlinked against the binary produced in the latest repo. If I switch back to linking against the older system files, the above command works just fine.

Is there any way I could had misconfigured the build for the LLVM repo, or perhaps a change between version 12 and 13 is getting in the way? Any advice would be appreciated.

Edit:

When moving the code.c argument to the start of the command I get many more undefined reference errors, here are the first 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)'

Here are the exact outputs of 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

Trying compilation and linking with g++ gives a new set of undefined references:

/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

Solution

  • Prefaced by the top comments ...

    Aha! llvm/clang are written in C++ and not C.

    The link is complaining about [amongst other things] not being able to resolve:

    operator new(unsigned long)
    

    This is a standard function provided by the c++ compiler [from an internal library]. It does not come from the LLVM libraries.

    It was not resolved because you're linking with gcc.

    Relink with g++ [or c++] (e.g.):

    cfg=llvm-config-<ver>
    gcc -I. $($cfg --cflags) -c code.c
    g++ -o code code.o $($cfg --ldflags --libs)
    

    That may be enough.

    Otherwise, you may have to rename code.c into code.cpp (i.e. your program may have to be C++ code) and compile it with g++ as well:

    cfg=llvm-config-<ver>
    g++ -I. $($cfg --cflags) -c code.cpp
    g++ -o code code.o $($cfg --ldflags --libs)
    

    UPDATE:

    Both suggestions here lead to the same set of new undefined reference errors that I've edited into the OP. – muke

    This did fix the C++ vs C issue.

    There are some other symbols that are unresolved:

    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
    

    The code is multithreaded and uses pthreads, and needs the library to resolve the various pthread_* symbols. So, add -lpthread to the end of the link command.

    crc32 et. al. are provided by zlib, so you may also need -lz.

    Also, dlopen et. al. is provided by -ldl (the dynamic linking library).

    And, set_curterm et. al. is provided by the curses library, so we may need -lcurses [or -lncurses instead]

    So, I'd try:

    cfg=llvm-config-<ver>
    g++ -I. $($cfg --cflags) -c code.cpp
    g++ -o code code.o $($cfg --ldflags --libs) -lz -lpthread -lcurses -ldl
    

    You may have to jiggle the order of these -l* options if that doesn't work, but give it a try as is.

    Or, as in lieu of that [as a last resort], you could put them in a linker group:

    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
    

    But, linker groups are [usually] more helpful with .a files that .so files.


    UPDATE #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?

    This is an extern in -lncurses. The way to see this is to look at the output of: 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

    If you do: ldd /usr/lib64/libncurses.6.so, it will tell which [shared] libraries it needs. One of them is [surprise ;-)]: /lib64/libtinfo.so.6

    As to the DSO issue, a google search on the phrase/sentence: DSO missing from command line, produces [amongst others] a link to:

    libpthread.so.0: error adding symbols: DSO missing from command line

    From that page, the issue is similar to your original problem of not putting the --libs argument as the last argument when linking.

    One of the solutions from that page is to use a linker group as I previously mentioned (e.g.) wrap the -l* options in the [aformentioned] -Wl,* options:

    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