Undefined Symbols when building LLVM

Hello all,

I have some custom transform passes written. Till now I am building them from the utils folder so there was no issue. But now I have created a seperated folder for the passes in Transform folder.

CMakeLists.txt (within the CustomPasses folder) :-

add_llvm_component_library(LLVMTransformCustomPasses
MyCPass1.cpp
MycPass2.cpp
MyCPass3.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms/CustomPasses

LINK_COMPONENTS
Analysis
Core
Support
)

In CMakeLists.txt (within the Transform folder) :-

add_subdirectory(CustomPasses)

Added header files in PassBuilder.cpp and Registered Pass names in PassRegister.def

I am getting the following linker error :-

ld.lld: error: undefined symbol: llvm::MyCPass1::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&)
>>> referenced by PassBuilder.cpp
>>>               PassBuilder.cpp.o:(llvm::detail::PassModel<llvm::Module, llvm::MyCPass1, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&)) in archive lib/libLLVMPasses.a

What exactly am I missing here?

This will “run” the CMakeLists.txt in that directory but it won’t tell any existing things to link to this new library you’ve defined in that subfolder.

So l think you’ll need to also add LLVMTransformCustomPasses in the LINK_COMPONENTS or equivalent of whatever needs this library. Likely you can just look for anything that links to the existing passes library, and add yours there too.

1 Like