Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libnl 3 (netlink library) undefined reference to nl* and genl*

Tags:

c

gcc

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

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

And to compile it, gcc $(pkg-config --cflags --libs libnl-3.0 libnl-genl-3.0) scan_access_points.c, which is identical to gcc -I/usr/include/libnl3 -lnl-genl-3 -lnl-3 scan_access_points.c

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?

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

like image 743
Jeon Avatar asked Jan 15 '15 08:01

Jeon


1 Answers

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) 
like image 110
nos Avatar answered Sep 28 '22 17:09

nos