[LLVMdev] link issue with InitializeNativeTarget

Zhoulai zell08v at gmail.com
Mon Apr 20 22:29:29 PDT 2015


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++ <source-file-of-the-user> `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

Voila.

Zhoulai


On Mon, Apr 20, 2015 at 7:03 PM, Zhoulai <zell08v at gmail.com> wrote:

> Hi,
>
> 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) {
>   InitializeNativeTarget();
>
> }
>
> 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.
>
> Zhoulai
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150420/db04432a/attachment.html>


More information about the llvm-dev mailing list