Reputation: 260
#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?
Upvotes: 1
Views: 2231
Reputation: 137547
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++.
Upvotes: 3