本文介绍了libnl 3(netlink库)对nl *和genl *的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译在此处编写的源代码,它会触发用户空间中的Wi-Fi主动扫描

I'm trying to compile a source code written here, which triggers Wi-Fi active scan in the user space.

它需要netlink库,所以我已经完成了sudo apt-get install libnl-3-dev libnl-genl-3-dev

It requires netlink library, so I've done sudo apt-get install libnl-3-dev libnl-genl-3-dev

并进行编译,gcc $(pkg-config --cflags --libs libnl-3.0 libnl-genl-3.0) scan_access_points.c,与gcc -I/usr/include/libnl3 -lnl-genl-3 -lnl-3 scan_access_points.c

但是编译失败,编号为undefined reference to 'SOMETHING'.日志在下面,您可以在此处看到它.

But the compile fails with numbers of undefined reference to 'SOMETHING'. The log is below and you can see it here.

/tmp/ccTQB59P.o: In function `family_handler':
scan_access_points.c:(.text+0xc8): undefined reference to `nlmsg_hdr'
scan_access_points.c:(.text+0xd0): undefined reference to `nlmsg_data'
scan_access_points.c:(.text+0xe5): undefined reference to `genlmsg_attrlen'
scan_access_points.c:(.text+0xf8): undefined reference to `genlmsg_attrdata'
scan_access_points.c:(.text+0x114): undefined reference to `nla_parse'
scan_access_points.c:(.text+0x133): undefined reference to `nla_data'
scan_access_points.c:(.text+0x146): undefined reference to `nla_len'
scan_access_points.c:(.text+0x160): undefined reference to `nla_len'
scan_access_points.c:(.text+0x171): undefined reference to `nla_data'
scan_access_points.c:(.text+0x18d): undefined reference to `nla_parse'
scan_access_points.c:(.text+0x1ad): undefined reference to `nla_len'
scan_access_points.c:(.text+0x1c3): undefined reference to `nla_data'
scan_access_points.c:(.text+0x1e3): undefined reference to `nla_get_u32'
scan_access_points.c:(.text+0x207): undefined reference to `nla_next'
scan_access_points.c:(.text+0x225): undefined reference to `nla_ok'
/tmp/ccTQB59P.o: In function `nl_get_multicast_id':
scan_access_points.c:(.text+0x266): undefined reference to `nlmsg_alloc'
scan_access_points.c:(.text+0x285): undefined reference to `nl_cb_alloc'
scan_access_points.c:(.text+0x2b2): undefined reference to `genl_ctrl_resolve'
scan_access_points.c:(.text+0x2eb): undefined reference to `genlmsg_put'
scan_access_points.c:(.text+0x318): undefined reference to `nla_put'
scan_access_points.c:(.text+0x334): undefined reference to `nl_send_auto_complete'
scan_access_points.c:(.text+0x367): undefined reference to `nl_cb_err'
scan_access_points.c:(.text+0x389): undefined reference to `nl_cb_set'
scan_access_points.c:(.text+0x3ab): undefined reference to `nl_cb_set'
scan_access_points.c:(.text+0x3c0): undefined reference to `nl_recvmsgs'
scan_access_points.c:(.text+0x3e0): undefined reference to `nl_cb_put'
scan_access_points.c:(.text+0x3ec): undefined reference to `nlmsg_free'
/tmp/ccTQB59P.o: In function `callback_trigger':
scan_access_points.c:(.text+0x628): undefined reference to `nlmsg_hdr'
scan_access_points.c:(.text+0x630): undefined reference to `nlmsg_data'
/tmp/ccTQB59P.o: In function `callback_dump':
scan_access_points.c:(.text+0x6d1): undefined reference to `nlmsg_hdr'
scan_access_points.c:(.text+0x6d9): undefined reference to `nlmsg_data'
scan_access_points.c:(.text+0x6f4): undefined reference to `genlmsg_attrlen'
scan_access_points.c:(.text+0x70a): undefined reference to `genlmsg_attrdata'
scan_access_points.c:(.text+0x729): undefined reference to `nla_parse'
scan_access_points.c:(.text+0x769): undefined reference to `nla_parse_nested'
scan_access_points.c:(.text+0x7bc): undefined reference to `nla_data'
scan_access_points.c:(.text+0x7f3): undefined reference to `nla_get_u32'
scan_access_points.c:(.text+0x813): undefined reference to `nla_len'
scan_access_points.c:(.text+0x824): undefined reference to `nla_data'
/tmp/ccTQB59P.o: In function `do_scan_trigger':
scan_access_points.c:(.text+0x8a5): undefined reference to `nl_socket_add_membership'
scan_access_points.c:(.text+0x8aa): undefined reference to `nlmsg_alloc'
scan_access_points.c:(.text+0x8ce): undefined reference to `nlmsg_alloc'
scan_access_points.c:(.text+0x8ef): undefined reference to `nlmsg_free'
scan_access_points.c:(.text+0x903): undefined reference to `nl_cb_alloc'
scan_access_points.c:(.text+0x924): undefined reference to `nlmsg_free'
scan_access_points.c:(.text+0x930): undefined reference to `nlmsg_free'
scan_access_points.c:(.text+0x970): undefined reference to `genlmsg_put'
scan_access_points.c:(.text+0x984): undefined reference to `nla_put_u32'
scan_access_points.c:(.text+0x99f): undefined reference to `nla_put'
scan_access_points.c:(.text+0x9b4): undefined reference to `nla_put_nested'
scan_access_points.c:(.text+0x9c0): undefined reference to `nlmsg_free'
scan_access_points.c:(.text+0x9e2): undefined reference to `nl_cb_set'
scan_access_points.c:(.text+0x9ff): undefined reference to `nl_cb_err'
scan_access_points.c:(.text+0xa21): undefined reference to `nl_cb_set'
scan_access_points.c:(.text+0xa43): undefined reference to `nl_cb_set'
scan_access_points.c:(.text+0xa64): undefined reference to `nl_cb_set'
scan_access_points.c:(.text+0xa7e): undefined reference to `nl_send_auto'
scan_access_points.c:(.text+0xab4): undefined reference to `nl_recvmsgs'
scan_access_points.c:(.text+0xaeb): undefined reference to `nl_geterror'
scan_access_points.c:(.text+0xb1c): undefined reference to `nl_recvmsgs'
scan_access_points.c:(.text+0xb51): undefined reference to `nlmsg_free'
scan_access_points.c:(.text+0xb5d): undefined reference to `nl_cb_put'
scan_access_points.c:(.text+0xb6e): undefined reference to `nl_socket_drop_membership'
/tmp/ccTQB59P.o: In function `main':
scan_access_points.c:(.text+0xb94): undefined reference to `nl_socket_alloc'
scan_access_points.c:(.text+0xba4): undefined reference to `genl_connect'
scan_access_points.c:(.text+0xbba): undefined reference to `genl_ctrl_resolve'
scan_access_points.c:(.text+0xbfb): undefined reference to `nlmsg_alloc'
scan_access_points.c:(.text+0xc35): undefined reference to `genlmsg_put'
scan_access_points.c:(.text+0xc49): undefined reference to `nla_put_u32'
scan_access_points.c:(.text+0xc6a): undefined reference to `nl_socket_modify_cb'
scan_access_points.c:(.text+0xc7d): undefined reference to `nl_send_auto'
scan_access_points.c:(.text+0xca0): undefined reference to `nl_recvmsgs_default'
scan_access_points.c:(.text+0xcaf): undefined reference to `nlmsg_free'
scan_access_points.c:(.text+0xcc1): undefined reference to `nl_geterror'
collect2: error: ld returned 1 exit status 

我不知道该如何解决这个问题.谁能给我一个解决方案或一个小提示吗?

I have no idea how could I solve this problem. Can anyone give me a solution or a tiny hint for this?

已在Ubuntu 14.04 LTS(内核:3.13.0-43-generic)上完成编译

Compile has been done on Ubuntu 14.04 LTS (kernel: 3.13.0-43-generic)

推荐答案

所链接的库-lnl-genl-3 -lnl-3自变量必须位于在命令行上使用它的代码之后.

Libraries you link in, the -lnl-genl-3 -lnl-3 arguments, must come after the code that uses it on the command line.

在您的情况下,最简单的方法是例如:

Which in your case can easiest be done with e.g. :

 gcc scan_access_points.c $(pkg-config --cflags --libs libnl-3.0 libnl-genl-3.0) 

这篇关于libnl 3(netlink库)对nl *和genl *的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 21:29