[cfe-users] linker errors against clang/llvm libraries

Adrian Ortega elfus0.1 at gmail.com
Mon Feb 10 20:15:15 PST 2014


Hello,

I am using Linux Mint 15 Olivia, and I installed the clang compiler and 
libclang-dev packages available in the repositories, they are version 3.2.

I am trying to compile and link the example from clang 
repositoryhttp://llvm.org/svn/llvm-project/cfe/tags/RELEASE_32/final/examples/clang-interpreter/main.cppas 
you can see it's from clang version 3.2.

When I compiled it with the command:

|$>  clang++  `llvm-config--cflags`  -c main.cpp|

I got the file main.o which contains some undefined symbols to 
clang/llvm libraries. I made sure it contains the symbols by using the 
nm command:

|$>  nm main.o|

A symbol from clang would be

|_ZN5clang16CompilerInstanceC1Ev|

Until now everything worked fine, until I tried to link the 'main.o' 
file with clang/llvm libraries. When I issue the command:

|$>  clang++  `llvm-config--ldflags`  main.o`llvm-config--libs`|

It fails with the following output (I just put the first error to not 
clutter this post):

|main.o:  In  function`main':
main.cpp:74:  undefined reference to`clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&,  clang::DiagnosticOptions*,  bool)'|

Basically I get a whole bunch of undefined references to clang 
libraries. I've tried researching on this and all I've found is that 
this has to do with the order you put the libraries flags on the command 
line. In addition to this, I also tried some other things:

 1. I tried a bunch of compiler flags, changing the order in which the
    linker flags appear, they never worked.
 2. I downloaded and compiled the LLVM and clang source code version
    3.2, and 3.4, same result: compiling works, linking fails. It's
    worth mentioning to say that for each version reordering the linker
    flags always gave different link errors (this is of course due to
    the way the link searches for libraries).

I ran out of ideas, and already spent 2 hours trying to compile a simple 
example from clang's repository, any help would be appreciated.

Thank you


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20140210/ad1430f3/attachment.html>


More information about the cfe-users mailing list