Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-21-2006, 06:39 AM   #1
LQ Newbie
Registered: Oct 2005
Posts: 28

Rep: Reputation: 15
error: undefined reference to `pcap_next_ex


I tried to execute a code which I downloaded.
here is the code
#include <pcap.h>
#include <stdio.h>

int main()
pcap_t *handle; /* Session handle */
char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */
struct pcap_pkthdr *header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */

/* Open the session in promiscuous mode */
handle = pcap_open_live("eth0", 65000, 0, 0, errbuf);
if (handle == 0) {
printf("Error in pcap_open_live: %s",errbuf);

/* Grab a packet */
int code = pcap_next_ex(handle, &header, &packet);
if (code < 0)
printf("Error in pcap_next_ex\n");

/* Print its length */
printf("Jacked a packet with length of %d",header->len );

/* And close the session */

When I compiled the code I got this error:

[root@CORE-2-02 examples]# gcc without2.c -lpcap
without2.c:31:2: warning: no newline at end of file
/tmp/cc0uKpD3.o(.text+0x72): In function `main':
: undefined reference to `pcap_next_ex'
collect2: ld returned 1 exit status

Can anybody say what is the problem.
I get this error whenever i use exported functions from pcap library

thanks and regards
cynthia thomas
Old 01-21-2006, 04:39 PM   #2
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Where is your pcap.h file? If it is in non-standard location you may have to do something like:
# gcc -I/usr/include/pcap without2.c -lpcap
Old 01-21-2006, 05:40 PM   #3
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
Seems that you have an old libpcap version


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
Undefined reference error jacques83 Programming 20 04-11-2013 07:23 AM
Getting undefined reference to main error?? Programming 14 07-29-2011 08:28 AM
Undefined reference error in MD5_Init() jacques83 Programming 3 11-13-2005 09:41 PM
gcc ld error. Undefined reference redness Linux - Software 4 02-08-2005 02:01 AM
undefined reference error Quest101 Programming 3 01-01-2005 12:27 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:41 PM.

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