即使nm指示该符号存在于共享库中,也是未定义的符号引用

这里有什么可能是错的? 我有以下简单的类:

#include "libmnl/libmnl.h" int main() { struct mnl_socket *a = mnl_socket_open(12); } 

运行一个简单的gcc编译( gcc -lmnl main.c )后,出现以下错误:

 /tmp/cch3GjuS.o: In function `main': main.c:(.text+0xe): undefined reference to `mnl_socket_open' collect2: ld returned 1 exit status 

共享库上运行nm显示它实际上被发现:

 aatteka@aatteka-Dell1:/tmp$ nm -D /usr/lib/libmnl.so | grep mnl_socket_open 0000000000001810 T mnl_socket_open 

这发生在Ubuntu 12.04上。 libmnl-devlibmnl0软件包已安装。 gccstrace输出表明ld正在使用那个* .so文件:

 [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.so", 0x7fff2a39b470) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.so", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.a", 0x7fff2a39b4d0) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/libmnl.a", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.so", 0x7fff2a39b470) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.so", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.a", 0x7fff2a39b4d0) = -1 ENOENT (No such file or directory) [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libmnl.a", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 10988] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmnl.so", {st_mode=S_IFREG|0644, st_size=18608, ...}) = 0 [pid 10988] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libmnl.so", O_RDONLY) = 7 

Solutions Collecting From Web of "即使nm指示该符号存在于共享库中,也是未定义的符号引用"