libnl 3(netlink 库)未定义对 nl* 和 genl* 的引用
libnl 3 (netlink library) undefined reference to nl* and genl*
我正在尝试编译 here 编写的源代码,它会在用户 space 中触发 Wi-Fi 主动扫描。
需要netlink库,所以我搞定了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'
。日志在下面,可以看到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
我不知道如何解决这个问题。谁能给我一个解决方案或一点提示?
已在 Ubuntu 14.04 LTS(内核:3.13.0-43-generic)
上完成编译
您 link 中的库,-lnl-genl-3 -lnl-3 参数,必须在命令行上使用它的代码之后。
在您的情况下,最简单的方法是使用例如:
gcc scan_access_points.c $(pkg-config --cflags --libs libnl-3.0 libnl-genl-3.0)
我正在尝试编译 here 编写的源代码,它会在用户 space 中触发 Wi-Fi 主动扫描。
需要netlink库,所以我搞定了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'
。日志在下面,可以看到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
我不知道如何解决这个问题。谁能给我一个解决方案或一点提示?
已在 Ubuntu 14.04 LTS(内核:3.13.0-43-generic)
上完成编译您 link 中的库,-lnl-genl-3 -lnl-3 参数,必须在命令行上使用它的代码之后。
在您的情况下,最简单的方法是使用例如:
gcc scan_access_points.c $(pkg-config --cflags --libs libnl-3.0 libnl-genl-3.0)