Linking issues on Linux, but not on Windows

Hi, I’m trying to compile my LLVM-based project. I’m using premake5 for generating build files, which works perfectly for windows (and compiles just fine over there as well), but after generating my build files with premake5 gmake and running make (GCC) I get a bunch of linker errors, containing various undefined references, the first one being:

undefined reference to `llvm::DominanceFrontierWrapperPass::ID'

I’m linking against the following libraries, in the following order:

LLVMAArch64AsmParser
LLVMAArch64CodeGen
LLVMAArch64Desc
LLVMAArch64Disassembler
LLVMAArch64Info
LLVMAArch64Utils
LLVMAMDGPUAsmParser
LLVMAMDGPUCodeGen
LLVMAMDGPUDesc
LLVMAMDGPUDisassembler
LLVMAMDGPUInfo
LLVMAMDGPUTargetMCA
LLVMAMDGPUUtils
LLVMARMAsmParser
LLVMARMCodeGen
LLVMARMDesc
LLVMARMDisassembler
LLVMARMInfo
LLVMARMUtils
LLVMAVRAsmParser
LLVMAVRCodeGen
LLVMAVRDesc
LLVMAVRDisassembler
LLVMAVRInfo
LLVMAggressiveInstCombine
LLVMAnalysis
LLVMAsmParser
LLVMAsmPrinter
LLVMBPFAsmParser
LLVMBPFCodeGen
LLVMBPFDesc
LLVMBPFDisassembler
LLVMBPFInfo
LLVMBinaryFormat
LLVMBitReader
LLVMBitWriter
LLVMBitstreamReader
LLVMCFGuard
LLVMCodeGen
LLVMCore
LLVMCoroutines
LLVMCoverage
LLVMDWARFLinker
LLVMDWARFLinkerParallel
LLVMDWP
LLVMDebugInfoCodeView
LLVMDebugInfoDWARF
LLVMDebugInfoGSYM
LLVMDebugInfoLogicalView
LLVMDebugInfoMSF
LLVMDebugInfoPDB
LLVMDemangle
LLVMDlltoolDriver
LLVMExecutionEngine
LLVMExtensions
LLVMFileCheck
LLVMFrontendHLSL
LLVMFrontendOpenACC
LLVMFrontendOpenMP
LLVMFuzzMutate
LLVMFuzzerCLI
LLVMGlobalISel
LLVMHexagonAsmParser
LLVMHexagonCodeGen
LLVMHexagonDesc
LLVMHexagonDisassembler
LLVMHexagonInfo
LLVMIRPrinter
LLVMIRReader
LLVMInstCombine
LLVMInstrumentation
LLVMInterfaceStub
LLVMInterpreter
LLVMJITLink
LLVMLTO
LLVMLanaiAsmParser
LLVMLanaiCodeGen
LLVMLanaiDesc
LLVMLanaiDisassembler
LLVMLanaiInfo
LLVMLibDriver
LLVMLineEditor
LLVMLinker
LLVMLoongArchAsmParser
LLVMLoongArchCodeGen
LLVMLoongArchDesc
LLVMLoongArchDisassembler
LLVMLoongArchInfo
LLVMMC
LLVMMCA
LLVMMCDisassembler
LLVMMCJIT
LLVMMCParser
LLVMMIRParser
LLVMMSP430AsmParser
LLVMMSP430CodeGen
LLVMMSP430Desc
LLVMMSP430Disassembler
LLVMMSP430Info
LLVMMipsAsmParser
LLVMMipsCodeGen
LLVMMipsDesc
LLVMMipsDisassembler
LLVMMipsInfo
LLVMNVPTXCodeGen
LLVMNVPTXDesc
LLVMNVPTXInfo
LLVMObjCARCOpts
LLVMObjCopy
LLVMObject
LLVMObjectYAML
LLVMOption
LLVMOrcJIT
LLVMOrcShared
LLVMOrcTargetProcess
LLVMPasses
LLVMPowerPCAsmParser
LLVMPowerPCCodeGen
LLVMPowerPCDesc
LLVMPowerPCDisassembler
LLVMPowerPCInfo
LLVMProfileData
LLVMRISCVAsmParser
LLVMRISCVCodeGen
LLVMRISCVDesc
LLVMRISCVDisassembler
LLVMRISCVInfo
LLVMRISCVTargetMCA
LLVMRemarks
LLVMRuntimeDyld
LLVMScalarOpts
LLVMSelectionDAG
LLVMSparcAsmParser
LLVMSparcCodeGen
LLVMSparcDesc
LLVMSparcDisassembler
LLVMSparcInfo
LLVMSupport
LLVMSymbolize
LLVMSystemZAsmParser
LLVMSystemZCodeGen
LLVMSystemZDesc
LLVMSystemZDisassembler
LLVMSystemZInfo
LLVMTableGen
LLVMTarget
LLVMTargetParser
LLVMTextAPI
LLVMTransformUtils
LLVMVEAsmParser
LLVMVECodeGen
LLVMVEDesc
LLVMVEDisassembler
LLVMVEInfo
LLVMVectorize
LLVMWebAssemblyAsmParser
LLVMWebAssemblyCodeGen
LLVMWebAssemblyDesc
LLVMWebAssemblyDisassembler
LLVMWebAssemblyInfo
LLVMWebAssemblyUtils
LLVMWindowsDriver
LLVMWindowsManifest
LLVMX86AsmParser
LLVMX86CodeGen
LLVMX86Desc
LLVMX86Disassembler
LLVMX86Info
LLVMX86TargetMCA
LLVMXCoreCodeGen
LLVMXCoreDesc
LLVMXCoreDisassembler
LLVMXCoreInfo
LLVMXRay
LLVMipo
clangAPINotes
clangARCMigrate
clangAST
clangASTMatchers
clangAnalysis
clangAnalysisFlowSensitive
clangAnalysisFlowSensitiveModels
clangBasic
clangCodeGen
clangCrossTU
clangDependencyScanning
clangDirectoryWatcher
clangDriver
clangDynamicASTMatchers
clangEdit
clangExtractAPI
clangFormat
clangFrontend
clangFrontendTool
clangHandleCXX
clangHandleLLVM
clangIndex
clangIndexSerialization
clangInterpreter
clangLex
clangParse
clangRewrite
clangRewriteFrontend
clangSema
clangSerialization
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangStaticAnalyzerFrontend
clangSupport
clangTooling
clangToolingASTDiff
clangToolingCore
clangToolingInclusions
clangToolingInclusionsStdlib
clangToolingRefactoring
clangToolingSyntax
clangTransformer

Additionally, here are the following libraries I’m linking against on Windows:

comdlg32.lib
delayimp.lib
gdi32.lib
kernel32.lib
ole32.dll
ole32.lib
oleaut32.lib
psapi.lib
shell32.dll
shell32.lib
user32.lib
uuid.lib
version.lib
winspool.lib
advapi32.lib

And here are the ones I link against on Linux:

dl     
pthread
m      
rt      

For anyone interested, my Premake script can be found here.

Note that all the libraries have been found, as I’m not getting any errors specifying that a library file cannot be found. Any help is greatly appreciated.

The best way to do linking with LLVM libraries is by making use of llvm-config You can tell it which components you want and it will give you the list of libraries. When using Camera, there even is a useful wrapper, see Building LLVM with CMake — LLVM 18.0.0git documentation

I recently assisted in upgrading a project where this was not used. It had a lot of linker errors since some libraries got split. Most of them where easily replaced by using the llvm_map_components_to_libnames function in CMake making it not just work though also future-proof.

1 Like

Thanks for the advice, I’ll make sure to use this! Is there perhaps a chance that LLVM on Linux requires different LLVM libs that LLVM on Windows?

Yep! There two libraries prefixed with Windows in this directory:

1 Like

Ah I see, thanks a bunch!

Apologies for reopening this question, but is there a way to use llvm-config with clang libraries, such as clangAST?