0

我在编译 libpcap 和 ROHC 库时遇到问题。当我运行给定程序时-

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

int main(int argc, char *argv[])
{
    char *dev, errbuf[PCAP_ERRBUF_SIZE];

    dev = pcap_lookupdev(errbuf);
    if (dev == NULL) {
        fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
        return(2);
    }
    printf("Device: %s\n", dev);
    return(0);
}



 manish@manish-HP-630-Notebook-PC:~$ gcc test.c -lpcap 
manish@manish-HP-630-Notebook-PC:~$ sudo ./a.out 
Device: eth0

但是当在程序下面运行时

#include <pcap/pcap.h>
int main(int argc, char *argv[])
{
pcap_t *handle;
handle = pcap_open_dead(DLT_LINUX_SLL, 5);
pcap_close(handle);
return 0;
}
output is compilation error
manish@manish-HP-630-Notebook-PC:~$ gcc -Wl,--verbose -o test_pcap -lpcap test_pcap.c

attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libpcap.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libpcap.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libpcap.so succeeded
-lpcap (/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libpcap.so)
attempt to open /tmp/cc0kpMzr.o succeeded
/tmp/cc0kpMzr.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.a succeeded
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so succeeded
-lgcc_s (/usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so)
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libc.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libc.a failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libc.so succeeded
opened script file /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libc.so
opened script file /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libc.so
attempt to open /lib/i386-linux-gnu/libc.so.6 succeeded
/lib/i386-linux-gnu/libc.so.6
attempt to open /usr/lib/i386-linux-gnu/libc_nonshared.a succeeded
(/usr/lib/i386-linux-gnu/libc_nonshared.a)elf-init.oS
attempt to open /lib/i386-linux-gnu/ld-linux.so.2 succeeded
/lib/i386-linux-gnu/ld-linux.so.2
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.so failed
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc.a succeeded
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so succeeded
-lgcc_s (/usr/lib/gcc/i686-linux-gnu/4.8/libgcc_s.so)
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/crtend.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/crtend.o
attempt to open /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crtn.o succeeded
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crtn.o
ld-linux.so.2 needed by /lib/i386-linux-gnu/libc.so.6
found ld-linux.so.2 at /lib/i386-linux-gnu/ld-linux.so.2
/tmp/cc0kpMzr.o: In function `main':
test_pcap.c:(.text+0x19): undefined reference to `pcap_open_dead'
test_pcap.c:(.text+0x29): undefined reference to `pcap_close'
collect2: error: ld returned 1 exit status

我也在rohc程序中发现了这个问题。

#include <stdlib.h>
 #include <stdio.h>
#include <rohc.h>

int main(int argc, char **argv)
{
 printf("ROHC version %s\n", rohc_version());
return 0;

}
manish@manish-HP-630-Notebook-PC:~$ gcc -o test_rohc_common -g -Wall -I/usr/local/include     -L/usr/local/lib/ -lrohc_common  test_rohc_common.c
/tmp/ccJfyUEg.o: In function `main':
/home/manish/test_rohc_common.c:7: undefined reference to `rohc_version'
collect2: error: ld returned 1 exit status

我也在检查两个库的安装。他们通过了所有测试,没有任何错误。我正在与 rohc 库社区联系,他们给出以下响应 1/gcc 从源代码正确构建 .o 对象,2/ld 无法将小程序与 ROHC 库链接,3/ld 正确找到 librohc*.so 文件, 4/ librohc*.so 文件似乎正确(ELF 32 位,符号都在那里)。请帮我。

4

0 回答 0