link issue with InitializeNativeTarget


Excuse me but I have struggled with a link issue when compiling this one-line program, “Hello.cpp”:

#include “llvm/Support/TargetSelect.h”
using namespace llvm;
int main(int argc, char **argv) {


I use this command line:

g++ -o Hello llvm-config --libs --cxxflags --ldflags …/src/Hello.cpp

The error message:

Hello.cpp:(.text._ZN4llvm22InitializeNativeTargetEv[_ZN4llvm22InitializeNativeTargetEv]+0x5): undefined reference to LLVMInitializeX86TargetInfo' Hello.cpp:(.text._ZN4llvm22InitializeNativeTargetEv[_ZN4llvm22InitializeNativeTargetEv]+0xa): undefined reference to LLVMInitializeX86Target’
Hello.cpp:(.text._ZN4llvm22InitializeNativeTargetEv[_ZN4llvm22InitializeNativeTargetEv]+0xf): undefined reference to `LLVMInitializeX86TargetMC’
collect2: error: ld returned 1 exit status

Any hint for the problem source? I am using LLVM 3.7 on a ubuntu 14.04 (VM). Thanks.

I have just solved the problem by myself.

For those who have the same problem as I did: just put your source file BEFORE those linraries.

g++ llvm-config ...

Following instrucitons on ‘ld’:

If any library A depends on symbols defined in library B, then library A should appear first in the list supplied to the linker