简体   繁体   English

链接器错误:对共享对象的未定义引用

[英]Linker error: undefined reference to shared object

I am trying to use an external library called iniparser in my C program. 我试图在我的C程序中使用一个名为iniparser的外部库。 I'm using gcc 4.4. 我正在使用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 . 我将iniparser库放在名为lib/ header文件的子目录中,在lib / iniparser / src中,并将库编译为lib/iniparser/libiniparser.so.0

I wrote a short Makefile to compile it, here's the output of make : 我写了一个简短的Makefile来编译它,这里是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 . 到GCC编译第一个电话smag_main.o成功,第二个编译agros.o ,第三个main.o The 4th call is the linker, that will link all those objects into an executable agros . 第四个调用是链接器,它将所有这些对象链接到可执行的agros It obviously fails. 它显然失败了。

It looks like it has problems locating iniparser.so at linking time. 看起来在链接时找到iniparser.so时遇到了问题。 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). (替代问题,如果有人能通过直接调用ld来解释如何进行链接,那就太好了)。

Try putting a symlink from libiniparser.so.0 to libiniparser.so 尝试将libiniparser.so.0的符号链接libiniparser.so.0 libiniparser.so

 cd lib/iniparser/
 ln -s libiniparser.so.0 libiniparser.so

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM