clangのlibtoolingチュートリアル (セクション「Put it together」)からコードをコンパイルしようとしました。コンパイルの動作:
g++ `llvm-config-3.5 --cxxflags` -fno-rtti -c test.cpp -o test.o
Clangから未定義の参照を取得したため、すべての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
15個の未定義の参照を取得します。
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
インストール済みパッケージ:
$ 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
誰かがエラーを解決または少なくとも再現できますか?
Cppファイルとclangライブラリの順序、およびclangライブラリの順序が重要です。を使用して正常にリンクしました
g++ `llvm-config --cxxflags --ldflags` tool.cpp $CLANG_LIBS `llvm-config --libs --system-libs` -o tool
cLANG_LIBSは次のように定義されました
CLANGLIBS="-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic -lclang"