Communication with clang-llvm

I am working on a small tool with clang / llvm, but I was not able to successfully get g ++ and gnu linker to properly link my code with clang.

my linker generates 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 compilation commands are as follows:

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 advice or recommendations would be welcome.

amuses, ct

PS: I learned some of the information on this page:

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

and he can do the trick, post a comment on this tip when I can.

Decision

using the clang code from this tutorial (which should have been modified to remove links to FileSystemOptions b / c clang / Basic / FileSystemOptions.h does not 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`

seems to have done the trick!

+5
2

llvm/clang, , . , .

, llvm-config, , : llvm-config --cxxflags --ldflags --libs backend.

, , , . , llvm, clang.

/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
+7

, ~/bin/llvm-config, ?

-l

`~/bin/llvm-config --cxxflags --ldflags --libs`

.o . , .

+4

All Articles