J'ai essayé de compiler le code de tutoriel libtooling de clang (section "Assemblez-le"). Travaux de compilation:
g++ `llvm-config-3.5 --cxxflags` -fno-rtti -c test.cpp -o test.o
Clang m'a donné des références indéfinies, alors j'ai même essayé de créer des liens avec toutes les bibliothèques de clang:
CLANG_LIBS="$(ls /usr/lib/llvm-3.5/lib/libclang* | sed -e 's/.*lib/-l/g' -e 's/\.a//g' -e 's/\.so.*//g' | tr '\n' ' ' )"
g++ `llvm-config-3.5 --ldflags --libs` $CLANG_LIBS test.o -o test
Je reçois environ 15 références non définies:
test.o: In function `ASTFrontendAction':
/usr/lib/llvm-3.5/include/clang/Frontend/FrontendAction.h:215: undefined reference to `clang::FrontendAction::FrontendAction()'
test.o: In function `SyntaxOnlyAction':
/usr/lib/llvm-3.5/include/clang/Frontend/FrontendActions.h:129: undefined reference to `vtable for clang::SyntaxOnlyAction'
test.o: In function `std::unique_ptr<clang::tooling::FrontendActionFactory, std::default_delete<clang::tooling::FrontendActionFactory> > clang::tooling::newFrontendActionFactory<clang::SyntaxOnlyAction>()::SimpleFrontendActionFactory::~SimpleFrontendActionFactory()':
/usr/lib/llvm-3.5/include/clang/Tooling/Tooling.h:309: undefined reference to `clang::tooling::FrontendActionFactory::~FrontendActionFactory()'
test.o: In function `~SimpleFrontendActionFactory':
/usr/lib/llvm-3.5/include/clang/Tooling/Tooling.h:309: undefined reference to `clang::tooling::FrontendActionFactory::~FrontendActionFactory()'
test.o: In function `clang::tooling::ClangTool::~ClangTool()':
/usr/lib/llvm-3.5/include/clang/Tooling/Tooling.h:252: undefined reference to `clang::tooling::ClangTool::clearArgumentsAdjusters()'
test.o: In function `llvm::RefCountedBase<clang::FileManager>::Release() const':
/usr/lib/llvm-3.5/include/llvm/ADT/IntrusiveRefCntPtr.h:55: undefined reference to `clang::FileManager::~FileManager()'
test.o: In function `~ClangTool':
/usr/lib/llvm-3.5/include/clang/Tooling/Tooling.h:252: undefined reference to `clang::tooling::ClangTool::clearArgumentsAdjusters()'
test.o: In function `llvm::RefCountedBase<clang::FileManager>::Release() const':
/usr/lib/llvm-3.5/include/llvm/ADT/IntrusiveRefCntPtr.h:55: undefined reference to `clang::FileManager::~FileManager()'
test.o: In function `main':
/home/t0161834/cprogs/nccheck/test.cpp:24: undefined reference to `clang::tooling::CommonOptionsParser::CommonOptionsParser(int&, char const**, llvm::cl::OptionCategory&, char const*)'
/home/t0161834/cprogs/nccheck/test.cpp:26: undefined reference to `clang::tooling::ClangTool::ClangTool(clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::string>)'
/home/t0161834/cprogs/nccheck/test.cpp:27: undefined reference to `clang::tooling::ClangTool::run(clang::tooling::ToolAction*)'
test.o: In function `OptionCategory':
/usr/lib/llvm-3.5/include/llvm/Support/CommandLine.h:150: undefined reference to `llvm::cl::OptionCategory::registerCategory()'
test.o: In function `__static_initialization_and_destruction_0':
/home/t0161834/cprogs/nccheck/test.cpp:18: undefined reference to `clang::tooling::CommonOptionsParser::HelpMessage'
/home/t0161834/cprogs/nccheck/test.cpp:18: undefined reference to `llvm::cl::extrahelp::extrahelp(char const*)'
/home/t0161834/cprogs/nccheck/test.cpp:21: undefined reference to `llvm::cl::extrahelp::extrahelp(char const*)'
test.o:(.data.rel.ro._ZTVZN5clang7tooling24newFrontendActionFactoryINS_16SyntaxOnlyActionEEESt10unique_ptrINS0_21FrontendActionFactoryESt14default_deleteIS4_EEvE27SimpleFrontendActionFactory[_ZTVZN5clang7tooling24newFrontendActionFactoryINS_16SyntaxOnlyActionEEESt10unique_ptrINS0_21FrontendActionFactoryESt14default_deleteIS4_EEvE27SimpleFrontendActionFactory]+0x20): undefined reference to `clang::tooling::FrontendActionFactory::runInvocation(clang::CompilerInvocation*, clang::FileManager*, clang::DiagnosticConsumer*)'
collect2: error: ld returned 1 exit status
Paquets installés:
$ dpkg -l "*clang*" | grep ii | awk '{ print $2 }' | tr '\n' ' '
clang-3.5 libclang-3.5-dev libclang-common-3.5-dev libclang1:AMD64 libclang1-3.4:AMD64 libclang1-3.5:AMD64
$ dpkg -l "*llvm*" | grep ii | awk '{ print $2 }' | tr '\n' ' '
libllvm3.4:AMD64 libllvm3.5:AMD64 llvm-3.5 llvm-3.5-dev llvm-3.5-runtime
Quelqu'un peut-il résoudre ou au moins reproduire l'erreur?
L'ordre des fichiers cpp et des bibliothèques clang est important, ainsi que l'ordre des bibliothèques clang. J'ai réussi à faire le lien en utilisant
g++ `llvm-config --cxxflags --ldflags` tool.cpp $CLANG_LIBS `llvm-config --libs --system-libs` -o tool
où CLANG_LIBS a été défini comme
CLANGLIBS="-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic -lclang"