链接到clang-llvm [英] Linking against clang-llvm
问题描述
我一直在使用clang / llvm的小工具,但是我没有能够成功获得g ++和gnu的链接器正确链接我的代码对clang。
I've been working on a small tool with clang/llvm but I haven't been able to successfully get g++ and gnu's linker to properly link my code against clang.
我的链接器生成以下错误:
my linker is generating the following errors:
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)'
我的编译命令如下所示:
my compile commands looks like this:
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
欢迎任何提示或建议。
干杯,
ct
cheers, ct
PS:我一直在探索此页面上的一些信息:
PS: I've been exploring some of the information on this page:
http://ubuntuforums.org/showthread.php?t=532693
使用cl代码本教程(这不得不进行修改,以消除FileSystemOptions引用b / C铛/基本/ FileSystemOptions.h不铛-2.8存在)的 http://clangtutorial.codeplex.com/
using clang code from this tutorial (which had to be modified to remove the references to FileSystemOptions b/c clang/Basic/FileSystemOptions.h doesn't exist in clang-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`
推荐答案
当我建立一些反对llvm / clang的东西时,这是我用来构建它。也许你可以比较两个构建行。
When I've built some stuff against llvm / clang, this is what I've used to build it. Perhaps you can compare the two build lines.
此外,我使用的llvm-config命令已经: llvm-config --cxxflags --ldflags --libs backend
。
Also, the llvm-config command I've used has been: llvm-config --cxxflags --ldflags --libs backend
.
最后,这可能部分与订购问题有关。你可能想包括LLVM库您包括铛库之前。
Finally, this is likely partially related to an ordering issue. You probably want to include the libraries for llvm before you include the clang libraries.
/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
这篇关于链接到clang-llvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!