LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   problem linking against libpcap library. (https://www.linuxquestions.org/questions/linux-software-2/problem-linking-against-libpcap-library-661406/)

brokencog 08-08-2008 09:09 AM

problem linking against libpcap library.
 
i have compiled and intalled the library, 0.9.8, without any seeming problems, however when i try to link any object files which reference a function in libpcap, i get an undefined reference.

here is the sample code:

<code>
#include <pcap.>

int main( void )
{
char err[PCAP_ERRBUF_SIZE];
char dev[1024];

dev = pcap_lookupdev( err );

return 0;

}

</code>

i can't make it any simpler than that -- the error exactly is:
pcap.c:(.text+0xab): undefined reference to `pcap_lookupdev'

if anyone has any ideas, i'll happily read them.

thanks, go easy,

-daniel

TB0ne 08-08-2008 12:14 PM

Do you have the libpcap development libraries installed too? The development libs are different than the actual libpcap software.

brokencog 08-08-2008 12:49 PM

hmm, i didn't think of that -- i'll try installing them and see if there is a difference.

stand by. *:).

-daniel

brokencog 08-08-2008 12:55 PM

oikay ... maybe i'm stupid -- i've gone to tcpdump.org's website, but the links to download the dev or current libraries are both 404. any other location to try ? i've done the usual look around to no avail.

-daniel

TB0ne 08-08-2008 02:43 PM

Quote:

Originally Posted by brokencog (Post 3241127)
oikay ... maybe i'm stupid -- i've gone to tcpdump.org's website, but the links to download the dev or current libraries are both 404. any other location to try ? i've done the usual look around to no avail.

-daniel

I don't see what version or distro of Linux you're using. Have you tried your distro's repository? http://www.rpmfind.net or http://rpm.pbone.net might also have it.

brokencog 08-08-2008 03:08 PM

i'll try those sites, thanks. i'm using Slackware 12.1, which has libpcap 0.9.8 bundled, which is what i'm currently linking against.

go easy,

-daniel

Valery Reznic 08-10-2008 05:19 AM

You didn't provide your Makefile.
How did you link your program ?
Do you specify -lpcap and -L with path to your libpcap location ?

brokencog 08-10-2008 12:39 PM

yes. make file is:
gcc -lpcap pcap.c

brokencog 08-10-2008 01:37 PM

okay ... well, i figured out some of the problem i was having. i had been using the following compile command:
gcc -lpcap pcap.c

instead i used:
gcc pcap.c -lpcap

which does link the files.
i had thought the needed libraries needed to precede the reference to objects within those libraries.


-daniel

Valery Reznic 08-10-2008 10:32 PM

Quote:

Originally Posted by brokencog (Post 3242777)
okay ... well, i figured out some of the problem i was having. i had been using the following compile command:
gcc -lpcap pcap.c

instead i used:
gcc pcap.c -lpcap

which does link the files.
i had thought the needed libraries needed to precede the reference to objects within those libraries.


-daniel

When linking with shared library order is not important.
When linking with static library (or just object files) undefined symboles looked at only in the yet unprocessed files. And processing is going from left to right.
In case of circular dependencies one ca use linker's -( and -) switches
but it make linking more slow.


All times are GMT -5. The time now is 11:15 PM.