tcpdump mailing list archives

Re: error with pcap_findalldevs()


From: Guy Harris <guy () alum mit edu>
Date: Mon, 19 Jan 2004 19:49:37 -0800


On Jan 15, 2004, at 10:35 AM, Mustafa Abu Sedera wrote:

I had pcap 0.6.1 installed on my redhat 8. I wanted to use the pcap_findalldevs funcion so i installed 0.8.1 on top of it (i don't know how to uninstall a non rpm package, i am noob still).

when I use the function I get an error: undefined reference to pcap_findalldevs(). I checked the pcap.h file (in 2 locations /usr/include and /usr/local/include) and found the function defined in there.

Strange is that:
1- the compiler doesn't complain about the definition of pcap_if_t which i think wasn't available in 0.6.1

If pcap.h defines "pcap_if_t", why would the compiler complain?

2- when i enter an invalid type argument(eg: int in place of char* of errBuf) the compiler displays: incorrect data type in argument of pcap_findalldevs().
And when I write 3 arguments it says: function takes 2 parameters.
This would mean that the compilers "knows" the function.

If "pcap.h" declares "pcap_findalldevs()" with a prototype, the compiler *does* know the function.

However, it's the *linker* that's complaining about the undefined reference, not the *compiler*. The compiler only looks at "pcap.h"; the linker looks at "libpcap.a" or "libpcap.so".

You probably still have libpcap 0.6.1's library installed, as well as having 0.8.1's library installed. (You might also have both header files installed - is the "pcap.h" in "/usr/include" the same as the one in "/usr/local/include"? If not, you do have both installed.)

There's probably one in "/usr/lib" and one in "/usr/local/lib".

You have to link with the 0.8.1 one, which is probably the one in "/usr/local/lib".

This means that, when you link your program, you need to have the option

        -L /usr/local/lib

in the compiler command line *before* the "-lpcap" option.

-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe


Current thread: