LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-08-2008, 09:09 AM   #1
brokencog
Member
 
Registered: Aug 2008
Location: united states
Distribution: slack 12.1
Posts: 36

Rep: Reputation: 15
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
 
Old 08-08-2008, 12:14 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,592

Rep: Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559
Do you have the libpcap development libraries installed too? The development libs are different than the actual libpcap software.
 
Old 08-08-2008, 12:49 PM   #3
brokencog
Member
 
Registered: Aug 2008
Location: united states
Distribution: slack 12.1
Posts: 36

Original Poster
Rep: Reputation: 15
hmm, i didn't think of that -- i'll try installing them and see if there is a difference.

stand by. *.

-daniel
 
Old 08-08-2008, 12:55 PM   #4
brokencog
Member
 
Registered: Aug 2008
Location: united states
Distribution: slack 12.1
Posts: 36

Original Poster
Rep: Reputation: 15
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
 
Old 08-08-2008, 02:43 PM   #5
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,592

Rep: Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559
Quote:
Originally Posted by brokencog View Post
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.
 
Old 08-08-2008, 03:08 PM   #6
brokencog
Member
 
Registered: Aug 2008
Location: united states
Distribution: slack 12.1
Posts: 36

Original Poster
Rep: Reputation: 15
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
 
Old 08-10-2008, 05:19 AM   #7
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 133Reputation: 133
You didn't provide your Makefile.
How did you link your program ?
Do you specify -lpcap and -L with path to your libpcap location ?
 
Old 08-10-2008, 12:39 PM   #8
brokencog
Member
 
Registered: Aug 2008
Location: united states
Distribution: slack 12.1
Posts: 36

Original Poster
Rep: Reputation: 15
yes. make file is:
gcc -lpcap pcap.c
 
Old 08-10-2008, 01:37 PM   #9
brokencog
Member
 
Registered: Aug 2008
Location: united states
Distribution: slack 12.1
Posts: 36

Original Poster
Rep: Reputation: 15
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

Last edited by brokencog; 08-10-2008 at 01:39 PM.
 
Old 08-10-2008, 10:32 PM   #10
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 666

Rep: Reputation: 133Reputation: 133
Quote:
Originally Posted by brokencog View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Library Linking problem IronBeagle Linux - Software 3 02-14-2006 12:10 PM
Still library linking problem The_Nerd Programming 19 05-20-2004 04:08 PM
Library linking problem The_Nerd Programming 10 04-26-2004 11:07 PM
libpcap linking error Hammo Linux - Networking 5 02-20-2003 07:20 AM


All times are GMT -5. The time now is 07:04 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration