[英]Linking against clang-llvm
我一直在研究一個使用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)'
我的編譯命令如下所示:
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
PS:我一直在探索這個頁面上的一些信息:
http://ubuntuforums.org/showthread.php?t=532693
它可以做到這一點,我會盡可能發表評論。
使用本教程中的clang代碼(必須修改以刪除對FileSystemOptions的引用b / c clang / Basic / FileSystemOptions.h在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構建一些東西時,這就是我用來構建它的東西。 也許你可以比較兩條構建線。
另外,我使用的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
我假設你在〜/ bin / llvm-config周圍有引號,對吧?
話雖這么說,移動-l選項和
`~/bin/llvm-config --cxxflags --ldflags --libs`
在命令行上的.o文件之后。 除非由前面的目標文件引用,否則不會從庫中取出Stuff。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.