【发布时间】:2014-12-17 06:43:25
【问题描述】:
我已经写了这段代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <linux/types.h>
#include <linux/netfilter.h>
#include <libnetfilter_queue/libnetfilter_queue.h>
int main(int argc, char **argv)
{
struct nfq_handle *h;
printf("opening library handle\n");
h = nfq_open();
nfq_close(h);
exit(0);
}
当我尝试编译时,它说:
/tmp/ccEv9MYS.o: In function `main':
test1.c:(.text+0x1a): undefined reference to `nfq_open'
test1.c:(.text+0x2a): undefined reference to `nfq_close'
collect2: ld returned 1 exit status
我尝试检查 gcc 是否找到了该库并且它是(当我修改 libnetfilter_queue 的包含时出现错误),我重新编译了该库并确定我正在调用的函数在其中。
如果您有任何线索感谢您的帮助
我用这个编译:
gcc -o test test1.c
我也试过了:
gcc -o test -lnetfilter_queue test1.c
gcc -o test -L/usr/local/lib test1.c
【问题讨论】:
-
netfilter 标签用于 netfilter_queue(顺便说一下这个标签丢失了),我把它放在以防有人遇到同样的问题,但我认为这是一个更普遍的问题
-
请出示您的编译声明。
-
感谢您指出这一点(我编辑了我的帖子以包含它)
-
你试过
gcc -o test test1.c -lnetfilter_queue吗? -
不严重,非常感谢(我白白浪费了 3 个小时)
标签: c linux ubuntu gcc netfilter