[LLVMdev] C API linking problem

Paul Melis llvm at assumetheposition.nl
Tue Sep 15 08:25:12 PDT 2009


Óscar Fuentes wrote:
> "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`

Thanks! Moving t.c to the front of the command-line fixes it (although
--ldflags still needs to go before --libs in the above line). And I need
to link with g++ instead of gcc.

I guess I didn't figure this one out because when you normally manually
specify libraries they always go *after* the source file argument.
Splitting the llvm-config call into a cxxflags and a --libs/--ldflags part
and putting the sources in between is probably cleaner in this respect.

Paul




More information about the llvm-dev mailing list