I have build clang,llvm,lld,openmp targets from the source code of llvm mono repo. I used the following commands:
cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang;lld;llvm;openmp" -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_LINKER=lld ../llvm -DCMAKE_INSTALL_PREFIX=~/git_repos/llvm-project/install
cmake --build . --target install
Once the build is done, I am trying to compile and generated the executable for a c++ file where I am using the following headers:
#include "clang/Frontend/ASTUnit.h"
#include "clang/Serialization/ASTWriter.h"
#include "clang/Serialization/InMemoryModuleCache.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Bitstream/BitstreamWriter.h"
The compile command is as follows:
g++ -I clang/include -I build/tools/clang/include -I build/include -I llvm/include test.cc $CLANGLIBS -lLLVM-14 -L build/lib
$CLANGLIBS variable is set to: -lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic -lcurses
When I run the above command, it is throwing lot of undefined references errors as follows:
/usr/bin/ld: build/lib/libclangTooling.a(AllTUsExecution.cpp.o):(.data.rel+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
/usr/bin/ld: build/lib/libclangTooling.a(AllTUsExecution.cpp.o): in function `llvm::Error::assertIsChecked()':
/home/rajkumar/git_repos/llvm-project/llvm/include/llvm/Support/Error.h:269: undefined reference to `llvm::Error::fatalUncheckedError() const'
/usr/bin/ld: build/lib/libclangTooling.a(ArgumentsAdjusters.cpp.o):(.data.rel+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
/usr/bin/ld: build/lib/libclangTooling.a(Execution.cpp.o): in function `clang::tooling::internal::createExecutorFromCommandLineArgsImpl(int&, char const**, llvm::cl::OptionCategory&, char const*)':
/home/rajkumar/git_repos/llvm-project/clang/lib/Tooling/Execution.cpp:76: undefined reference to `llvm::toString[abi:cxx11](llvm::Error)'
/usr/bin/ld: build/lib/libclangTooling.a(Execution.cpp.o):(.data.rel+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
/usr/bin/ld: build/lib/libclangTooling.a(StandaloneExecution.cpp.o):(.data.rel+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
/usr/bin/ld: build/lib/libclangTooling.a(Tooling.cpp.o): in function `clang::tooling::runToolOnCodeWithArgs(std::unique_ptr<clang::FrontendAction, std::default_delete<clang::FrontendAction> >, llvm::Twine const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, llvm::Twine const&, llvm::Twine const&, std::shared_ptr<clang::PCHContainerOperations>, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)':
Along with clang libraries I have linked all the LLVM libraries as well(which I got using llvm-config tool llvm-config --libs
)
Even after trying a couple of stack-overflow threads, it seems not solving the issue for me: Compilation failing on EnableABIBreakingChecks
I really appreciate any help I can get, I am new to llvm source code compilation and usage.
Thanks
Rajkumar Ananthu.
EDIT:
The reason why I am using g++ to compile the input file is that g++ is my default compiler and the whole clang & LLVM source code is compiled using g++ only.
I found a thread from LLVM discourse channel and I think this solves my issue:
https://discourse.llvm.org/t/undefined-reference-only-when-including-astmatchers/67687
The solution in a statement is that I have to add -lclang-cpp also to the $CLANGLIBS variable or I have to link -lclang-cpp while generating the executable.
Hope this might help some one who is facing a similar issue.
Thanks
Rajkumar Ananthu.