Reputation: 5878
I am trying to use an external library called iniparser
in my C program. I'm using gcc 4.4.
I put the iniparser
library in a subdirectory called lib/
header files are in lib/iniparser/src and the library is compiled to lib/iniparser/libiniparser.so.0
.
I wrote a short Makefile to compile it, here's the output of make
:
gcc -Wall -Wextra -Werror -c -I include/ src/smag_main.c -L lib/iniparser -liniparser -I lib/iniparser/src
gcc -Wall -Wextra -Werror -c -I include/ -L lib/iniparser -liniparser -I lib/iniparser/src src/agros.c
gcc -Wall -Wextra -Werror -c -I include/ -L lib/iniparser -liniparser -I lib/iniparser/src src/main.c
gcc -Wall -Wextra -Werror -L lib/iniparser -liniparser -o agros smag_main.o main.o agros.o
smag_main.o: In function `sec_haskey':
smag_main.c:(.text+0xa9): undefined reference to `iniparser_find_entry'
smag_main.o: In function `parse_config':
smag_main.c:(.text+0x153): undefined reference to `iniparser_load'
smag_main.c:(.text+0x18b): undefined reference to `iniparser_getint'
smag_main.c:(.text+0x1c6): undefined reference to `iniparser_getstring'
smag_main.c:(.text+0x202): undefined reference to `iniparser_getstring'
smag_main.c:(.text+0x261): undefined reference to `iniparser_getstring'
smag_main.c:(.text+0x2c2): undefined reference to `iniparser_getint'
smag_main.c:(.text+0x2d5): undefined reference to `iniparser_freedict'
collect2: ld returned 1 exit status
make: *** [agros] Error 1
First call to gcc compiles smag_main.o
successfully, the second one compiles agros.o
and the third one main.o
. The 4th call is the linker, that will link all those objects into an executable agros
. It obviously fails.
It looks like it has problems locating iniparser.so
at linking time. How's my call wrong?
I am confused.
(Alternate question, if anyone could explain how to the linking by calling ld
directly it would be great).
Upvotes: 2
Views: 2626
Reputation: 1447
Try putting a symlink from libiniparser.so.0
to libiniparser.so
cd lib/iniparser/
ln -s libiniparser.so.0 libiniparser.so
Upvotes: 4