Referências indefinidas compilando o tutorial clang em 14.04.2

4

Eu tentei compilar o código do tutorial de libtooling do clang (seção "Coloque junto"). Compilando trabalhos:

g++ 'llvm-config-3.5 --cxxflags' -fno-rtti  -c test.cpp -o test.o

Eu obtive referências indefinidas do clang, então eu até tentei ligar contra todas as bibliotecas 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

Eu recebo 15 referências indefinidas:

    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

Pacotes instalados:

$ 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

Alguém pode resolver ou pelo menos reproduzir o erro?

    
por Johannes 11.02.2016 / 07:35

1 resposta

6

A ordem do arquivo cpp e das bibliotecas clang é importante, assim como a ordem das bibliotecas clang. Eu fiz isso com sucesso link usando

g++ 'llvm-config --cxxflags --ldflags' tool.cpp $CLANG_LIBS 'llvm-config --libs --system-libs' -o tool

em que CLANG_LIBS foi definido como

CLANGLIBS="-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic -lclang"
    
por Filip Maric 21.02.2016 / 17:43