[LLVMdev] C API linking problem

Óscar Fuentes ofv at wanadoo.es
Tue Sep 15 08:27:12 PDT 2009


"Paul Melis" <llvm at assumetheposition.nl> writes:

>>> 15:29|melis at juggle2:~/c/llvmpy> gcc -W -Wall -o blah `llvm-config
>>> --cflags
>>> --ldflags --libs all` t.c
>>> /tmp/ccs4MbKp.o: In function `main':
>>> t.c:(.text+0x21): undefined reference to `LLVMContextCreate'
>>> collect2: ld returned 1 exit status
>>>
>>> 15:29|melis at juggle2:~/c/llvmpy> nm ~/llvm/lib/libLLVMCore.a | grep
>>> LLVMContextCreate
>>> 00001bc0 T LLVMContextCreate
>>
>> Try this:
>>
>> gcc t.c -W -Wall -o blah `llvm-config --cflags --libs all --ldflags`
>
> Are you sure that's what you meant? Now the linker can't find anything
> anymore and I get tons of unresolved symbols.

That is because -L comes after the LLVM libraries.

Try

gcc t.c -W -Wall -o blah `llvm-config --cflags --ldflags --libs all`

However, if your linker is sensitive to library order, you may get
unresolved externals for -lpthread and other system libraries that
are list before the LLVM libraries on the llvm-config output.

If that happens try

gcc t.c -W -Wall -o blah -L/home/melis/llvm/lib `llvm-config --cflags --libs all --ldflags`

HTH.

-- 
Óscar




More information about the llvm-dev mailing list