【发布时间】:2020-07-19 11:21:50
【问题描述】:
-
我在某个库的.c源代码中添加了一个函数,并在相应的.h文件中添加了函数头,然后安装了整个程序(./configure;make;make install),没有错误。
-
用 nm 检查我的函数是否存在于共享库 (.so) 中(由上面的编译生成):它表示该函数在那里
-
在编译调用我的自定义函数并将其与库链接的程序时,我收到以下错误:
$ gcc -o test test.c -lnftables /tmp/cc47BbcQ.o: In function `main': test.c:(.text+0x11): undefined reference to print_hello() collect2: error: ld returned 1 exit status
- 但是当编译一个程序时没有任何引用我的自定义函数时,它可以正常运行并且没有错误。
系统:Debian 9 延伸
内存:8GB
CPU:Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
库:nftables 9.4(来源here)
gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
【问题讨论】:
-
您应该包含
nm调用的输出,将其限制在函数的定义中。我猜测被报告的类型将是t,而不是T- 即在库本地,而不是导出 -
@Petesh:你说得对
# nm /usr/local/lib/libnftables.so |grep print_hello 0000000000042df0 t print_hello那我该怎么办?
标签: c