Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am using Ubuntu 12.10 32-bit.In my project I am using ROHC and libpcap library. when I run simple pcap program like-

#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);
}

it is give a proper ouput. but when I run this program-

#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;
}

I found this type of error

ttempt 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/cca6Llt3.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

another program also give same error-

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

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

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

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

I also check libpcap and ROHC library they are properly install and passes all test without any error. I think that in my system ld creates a problem in linking. give any suggestion regarding this.

share|improve this question
1  
You should ask this on stackoverflow.com –  Rinzwind Sep 9 '13 at 14:06
add comment

closed as off-topic by Rinzwind, Kevin Bowen, Eliah Kagan, Braiam, Eric Carvalho Sep 10 '13 at 11:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Rinzwind, Kevin Bowen, Eliah Kagan, Braiam, Eric Carvalho
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

You need to link pcap in the compiler:

braiam@bt:~/lab$ gcc other.c 
/tmp/ccZIWTOK.o: In function `main':
other.c:(.text+0x19): undefined reference to `pcap_open_dead'
other.c:(.text+0x29): undefined reference to `pcap_close'
collect2: error: ld returned 1 exit status
braiam@bt:~/lab$ gcc -lpcap other.c 
braiam@bt:~/lab$ 

I'm not willing to install the roch libraries, but if it gives you the same error, the second one should work too.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.