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
any tips or advice would be welcomed.
cheers, ct
PS: I've been exploring some of the information on this page:
http://ubuntuforums.org/showthread.php?t=532693
and it might do the trick, will post a comment on that tip when I can.
Solution
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`
seemed to do the trick!