gpt4 book ai didi

c++ - 你如何使用 libnl nl_sock?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:59:44 31 4
gpt4 key购买 nike

#include <netlink/socket.h>
#include <netlink/netlink.h>
struct nl_sock *sock;

sock = nl_socket_alloc();

上面的代码总是编译失败,报如下错误: /home/micah/Documents/C++/Socket_fun/Socket_fun/src/main.cpp|5|错误:‘sock’没有命名类型

我从 libnl 示例中得到这个,但它不起作用,我想知道,执行此操作的正确方法是什么?

最佳答案

该代码必须在函数中,您不能在函数上下文之外开始调用函数:

int main()
{
struct nl_sock *sock;
sock = nl_socket_alloc();
}

还有,你用什么编译的?我建议将其编译为 C,而不是 C++。

关于c++ - 你如何使用 libnl nl_sock?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8675504/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com