clang - How to fix missing libs while compiling with llvm-config? -
i'm trying compile code uses llvm/clang api compile 'hello_world' llvm ir:
#include <iostream> #include <clang/driver/compilation.h> #include <clang/driver/driver.h> #include <clang/frontend/textdiagnosticprinter.h> #include <llvm/support/host.h> #include <llvm/support/program.h> #include <llvm/support/raw_ostream.h> using namespace std; using namespace clang; using namespace clang::driver; int main(int argc, char** argv) { std::cout << "starting ----" << std::endl; // [clang -s -emit-llvm ./test/hello_world.cpp] // arguments pass clang driver: // clang getinmemory.c -lcurl -v // path c file string clangpath = "clang"; string inputpath = "./test/hello_world.cpp"; string outputpath = "hello_world.ll"; vector<const char *> args; args.push_back(clangpath.c_str()); args.push_back("-s"); args.push_back("-emit-llvm"); args.push_back(inputpath.c_str()); // clang driver needs diagnosticsengine can report problems clang::diagnosticoptions *options = new clang::diagnosticoptions(); //clang::textdiagnosticprinter *diagclient = new clang::textdiagnosticprinter(llvm::errs(), options); clang::intrusiverefcntptr<clang::diagnosticids> diagid(new clang::diagnosticids()); clang::diagnosticsengine diags(diagid, options); // create clang driver clang::driver::driver thedriver(args[0], llvm::sys::getdefaulttargettriple(), outputpath, diags); // c++ code //thedriver.ccciscxx = true; // create set of actions perform clang::owningptr<clang::driver::compilation> compilation(thedriver.buildcompilation(args)); // print set of actions thedriver.printactions(*compilation); std::cout << "done ----" << std::endl; // carry out actions int res = 0; smallvector<std::pair<int, const command *>, 4> failingcommands; if (compilation) res = thedriver.executecompilation(*compilation, failingcommands); // report problems /* if (res < 0) thedriver.generatecompilationdiagnostics(*compilation, failingcommands); */ (smallvectorimpl< std::pair<int, const command *> >::iterator = failingcommands.begin(), ie = failingcommands.end(); != ie; ++it) { int commandres = it->first; const command *failingcommand = it->second; if (!res) res = commandres; if (commandres < 0 || commandres == 70) { thedriver.generatecompilationdiagnostics(*compilation, failingcommand); break; } } return res; }
i decided use llvm-config
correct compile/link params, i'm having link error (it seems libs still missing in -l
):
mba-anton:build asmirnov$ clang++ `llvm-config --cxxflags` `llvm-config --ldflags` `llvm-config --libs all` ../clang_ir.cpp undefined symbols architecture x86_64: "clang::diagnosticids::diagnosticids()", referenced from: _main in clang_ir-fb4166.o "clang::diagnosticids::~diagnosticids()", referenced from: llvm::refcountedbase<clang::diagnosticids>::release() const in clang_ir-fb4166.o "clang::diagnosticsengine::diagnosticsengine(llvm::intrusiverefcntptr<clang::diagnosticids> const&, clang::diagnosticoptions*, clang::diagnosticconsumer*, bool)", referenced from: _main in clang_ir-fb4166.o "clang::diagnosticsengine::~diagnosticsengine()", referenced from: _main in clang_ir-fb4166.o "clang::driver::compilation::~compilation()", referenced from: llvm::owningptr<clang::driver::compilation>::~owningptr() in clang_ir-fb4166.o "clang::driver::driver::buildcompilation(llvm::arrayref<char const*>)", referenced from: _main in clang_ir-fb4166.o "clang::driver::driver::generatecompilationdiagnostics(clang::driver::compilation&, clang::driver::command const*)", referenced from: _main in clang_ir-fb4166.o "clang::driver::driver::driver(llvm::stringref, llvm::stringref, llvm::stringref, clang::diagnosticsengine&)", referenced from: _main in clang_ir-fb4166.o "clang::driver::driver::~driver()", referenced from: _main in clang_ir-fb4166.o "clang::driver::driver::printactions(clang::driver::compilation const&) const", referenced from: _main in clang_ir-fb4166.o "clang::driver::driver::executecompilation(clang::driver::compilation const&, llvm::smallvectorimpl<std::__1::pair<int, clang::driver::command const*> >&) const", referenced from: _main in clang_ir-fb4166.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) mba-anton:build asmirnov$
oh, forgot add clang libclang...a
libs llvm-config
relates llvm , not know clang.
Comments
Post a Comment