#include <netlink/socket.h>
#include <netlink/netlink.h>
struct nl_sock *sock;
sock = nl_socket_alloc();
The above code always fails to compile with the following error: /home/micah/Documents/C++/Socket_fun/Socket_fun/src/main.cpp|5|error: 'sock' does not name a type
I got this from the libnl example, and as it doesn't work, I am wondering, what is the correct way to do this?
That code has to be in a function, you can't just start calling functions outside the context of a function:
int main()
{
struct nl_sock *sock;
sock = nl_socket_alloc();
}
Also, what are you compiling with? I would recommend compiling it as C, not C++.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.