链接clang-llvm

ct_*_*ct_ 5 c++ llvm clang llvm-clang

我一直在研究一个使用clang/llvm的小工具,但是我无法成功地获取g ++和gnu的链接器来正确链接我的代码与clang.

我的链接器生成以下错误:

undefined reference to `clang::FileManager::~FileManager()'

undefined reference to `clang::FileManager::FileManager()'

undefined reference to `llvm::sys::getHostTriple()'

undefined reference to `clang::Diagnostic::Diagnostic(clang::DiagnosticClient*)'

undefined reference to `llvm::outs()'

undefined reference to `clang::TargetInfo::CreateTargetInfo(clang::Diagnostic&, clang::TargetOptions&)'

undefined reference to `clang::SourceManager::getOrCreateContentCache(clang::FileEntry const*)'

undefined reference to `clang::SourceManager::createFileID(clang::SrcMgr::ContentCache const*, clang::SourceLocation, clang::SrcMgr::CharacteristicKind, unsigned int, unsigned int)'
Run Code Online (Sandbox Code Playgroud)

我的编译命令如下所示:

g++ -g -fno-rtti -I~/llvm-2.8/tools/clang-2.8/include \
  -I~/llvm-2.8/llvm/include \
  `~/bin/llvm-config --cxxflags` \
  -c Frontend.cpp

g++ -g -fno-rtti -I~/llvm-2.8/tools/clang-2.8/include \
  -I~/llvm-2.8/llvm/include \
  `~/bin/llvm-config --cxxflags` \
  -c exec.cpp

g++ -I~/llvm-2.8/tools/clang-2.8/include \
    -I~/llvm-2.8/llvm/include -L~/opt/lib/ \
    -g -fno-rtti -lclangDriver -lclangAnalysis \
    -lclangFrontend -lclangSema -lclangAST -lclangParse \
    -lclangLex -lclangBasic  \
    `~/bin/llvm-config --cxxflags --ldflags --libs`  \
    Frontend.o exec.o -o run
Run Code Online (Sandbox Code Playgroud)

任何提示或建议都会受到欢迎.

干杯,ct

PS:我一直在探索这个页面上的一些信息:

http://ubuntuforums.org/showthread.php?t=532693

它可以做到这一点,我会尽可能发表评论.

使用铛代码从本教程(其必须被修改以除去对FileSystemOptions B/C铛的参考文献/基本/ FileSystemOptions.h不铛-2.8存在):http://clangtutorial.codeplex.com/

g++ tutorial1.cpp -g -fno-rtti -lclangFrontend -lclangDriver       \
    -lclangCodeGen -lclangSema -lclangChecker -lclangAnalysis      \
    -lclangRewrite -lclangAST -lclangParse -lclangLex -lclangBasic \
    -lLLVMSupport -lLLVMSystem -I~/opt/include/                    \
    `llvm-config --cxxflags --ldflags --libs all`
Run Code Online (Sandbox Code Playgroud)

似乎做了伎俩!

Bil*_*nch 7

当我为llvm/clang构建一些东西时,这就是我用来构建它的东西.也许你可以比较两条构建线.

另外,我使用的llvm-config命令是:llvm-config --cxxflags --ldflags --libs backend.

最后,这可能部分与订购问题有关.在包含clang库之前,您可能希望包含llvm的库.

/usr/bin/g++                                                              \
    -fno-exceptions -fno-rtti -fno-common                                 \
    -I/Users/wlynch/Homebrew/include                                      \
    -DNDEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS \
    ../src/main.cpp -c -o src/main.cpp.0.o

/usr/bin/g++
     src/main.cpp.0.o -o /Users/wlynch/Dropbox/Clang/Indexer/build/main               \
     -L/Users/wlynch/Homebrew/lib -L/Users/wlynch/Homebrew/lib                        \
     -lpthread -lm                                                                    \
     -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG     \
     -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine \
     -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMCore            \
     -lLLVMX86AsmPrinter -lLLVMMC -lLLVMX86Info -lLLVMSupport -lLLVMSystem            \
     -lclangAST -lclangAnalysis -lclangBasic -lclangChecker -lclangCodeGen            \
     -lclangDriver -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex        \
     -lclangParse -lclangRewrite -lclangSema -lclangSerialization
Run Code Online (Sandbox Code Playgroud)