Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PCAP没有';我不能在克莱恩工作_C_Pcap_Clion - Fatal编程技术网

PCAP没有';我不能在克莱恩工作

PCAP没有';我不能在克莱恩工作,c,pcap,clion,C,Pcap,Clion,对于我的作业,我需要使用libpcap运行C/C++代码。我正在使用CLion 1.2。当我尝试运行测试代码时,我会收到消息 未定义对“pcap\u open\u offline”的引用 未定义对“pcap\U next”的引用 这是密码 #include <stdio.h> #include <pcap/pcap.h> const u_char *packet; int main() { char errbuf[PCAP_ERRBUF_SIZE];

对于我的作业,我需要使用libpcap运行C/C++代码。我正在使用CLion 1.2。当我尝试运行测试代码时,我会收到消息

未定义对“pcap\u open\u offline”的引用

未定义对“pcap\U next”的引用

这是密码

#include <stdio.h>
#include <pcap/pcap.h>

const u_char *packet;


int main() {


    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t *handle = pcap_open_offline("/home/alex/Downloads/priklad.pcap", errbuf);

    struct pcap_pkthdr packet_header;
    packet = pcap_next(handle, &packet_header);


    return 0;
}

我的问题是,我做错了什么?图书馆在哪里?我如何找到它并正确链接它而不必每次使用gcc编译?

您永远不会链接到
libpca

更改您的线路:

target_link_libraries(PKS1 ${usr/include})

您可能还希望更改为:

find_package(PCAP REQUIRED)
如果找不到
libpcap
,则在运行
cmake
时出错,而不是在编译步骤中出错

target_link_libraries(PKS1 ${PCAP_LIBRARY})
find_package(PCAP REQUIRED)