1821413 Members
2444 Online
109633 Solutions
New Discussion юеВ

ld: cannot find -lpcap

 
SOLVED
Go to solution
Geoff Wild
Honored Contributor

ld: cannot find -lpcap

Trying to compile dnstop:

http://dns.measurement-factory.com/tools/dnstop/

Had to modify Makefile to:

CFLAGS=-g -Wall -I/usr/local/include -I/usr/local/lib
PROG=dnstop
DATE!=date +%Y%m%d
CC=gcc

SRCS= $(PROG).c \
known_tlds.h

# You may need to uncomment this, esp on Solaris
XTRALIBS= #-lnsl -lresolv -lsocket

all: $(PROG)

$(PROG): $(PROG).o
$(CC) $(CFLAGS) -o $@ $(PROG).o -lpcap -lcurses $(XTRALIBS)

clean:
rm -f $(PROG) $(PROG).o $(PROG).core $(PROG).c~

tar:
mkdir $(PROG)-$(DATE)
cp -p LICENSE CHANGES $(SRCS) dnstop.8 Makefile $(PROG)-$(DATE)
tar czvf $(PROG)-$(DATE).tar.gz $(PROG)-$(DATE)
chmod 444 $(PROG)-$(DATE).tar.gz
rm -rf $(PROG)-$(DATE)
sha1:root:/usr/local/src/dnstop-20040309 # cat Makefile
CFLAGS=-g -Wall -I/usr/local/include -I/usr/local/lib
PROG=dnstop
DATE!=date +%Y%m%d
CC=gcc

SRCS= $(PROG).c \
known_tlds.h

# You may need to uncomment this, esp on Solaris
XTRALIBS= #-lnsl -lresolv -lsocket

all: $(PROG)

$(PROG): $(PROG).o
$(CC) $(CFLAGS) -o $@ $(PROG).o -lpcap -lcurses $(XTRALIBS)

clean:
rm -f $(PROG) $(PROG).o $(PROG).core $(PROG).c~

tar:
mkdir $(PROG)-$(DATE)
cp -p LICENSE CHANGES $(SRCS) dnstop.8 Makefile $(PROG)-$(DATE)
tar czvf $(PROG)-$(DATE).tar.gz $(PROG)-$(DATE)
chmod 444 $(PROG)-$(DATE).tar.gz
rm -rf $(PROG)-$(DATE)

Using gcc version 3.3.2

I installed these first:
libpcap-0.8.1-sd-11.00.depot
tcpdump-3.8.1-sd-11.00.depot
bison-1.875-sd-11.00.depot
flex-2.5.4a-sd-11.00.depot

I try make all from

/usr/local/src/dnstop-20040309

gcc -g -Wall -I/usr/local/include -I/usr/local/lib -o dnstop dnstop.o -lpcap -lcurses
/opt/pa20_64/bin/../lib/gcc-lib/hppa64-hp-hpux11.11/3.3.2/../../../../hppa64-hp-hpux11.11/bin/ld: cannot find -lpcap
collect2: ld returned 1 exit status
*** Error exit code 1

Stop.

I'm compiling as root on HP-UX 11.11.

Thanks...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
19 REPLIES 19
A. Clay Stephenson
Acclaimed Contributor

Re: ld: cannot find -lpcap

I would take the box at its word. Either install libpcap or alter the linker's library search path to include the location of your libpcap file. It's also possible that libpcap isn't even needed so youi could try altering the makefile to remove the -lpcap statement. -lpcap is linker shorthand for libpcap.a or libpcap.sl in the directories specifed by the linkers library search path.

http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/libpcap-0.8.1/
If it ain't broke, I can fix that.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Yes, I did install libpcap...

I had to add -I/usr/local/include -I/usr/local/lib to the CFLAGS for it to see pcap.h and pcap-bpf.h

libpcap.a and libpcap.sl are in /usr/local/lib/

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Okay - getting somewhere:

# export LPATH=/usr/local/lib:/usr/lib
# make all
gcc -g -Wall -I/usr/local/include -I/usr/local/lib -o dnstop dnstop.o -lpcap -lcurses
/usr/lib/crt0.o: file not recognized: File format not recognized
collect2: ld returned 1 exit status
*** Error exit code 1

Stop.


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
H.Merijn Brand (procura
Honored Contributor

Re: ld: cannot find -lpcap

you do not by accident run a 64bit gcc, now do you?

Hmm, I guess you do.
Make your life easier and rename is to gcc64

64bit objects do NOT mix with 32bit objects

all objects (including crt0.o) in /usr/lib are 32 bit
64bit objects are in /usr/lib/pa20_64

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Ah ha - Merijn - I do:

# which gcc
/opt/pa20_64/bin/gcc


So I tried:

export LPATH=/usr/local/lib

Now I get:

# make all
gcc -g -Wall -I/usr/local/include -I/usr/local/lib -o dnstop dnstop.o -lpcap -lcurses
/usr/local/lib/libpcap.sl: file not recognized: File format not recognized
collect2: ld returned 1 exit status
*** Error exit code 1

Stop.

# file /usr/local/lib/libpcap.sl
/usr/local/lib/libpcap.sl: PA-RISC1.1 shared library


# what /usr/local/lib/libpcap.sl
/usr/local/lib/libpcap.sl:
$Header: /tcpdump/master/libpcap/fad-gifc.c,v 1.4.2.1 2003/11/15 23:26:39 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/inet.c,v 1.58.2.1 2003/11/15 23:26:41 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/gencode.c,v 1.193.2.2 2003/12/18 20:37:12 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/optimize.c,v 1.76.2.3 2003/12/22 00:26:36 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/etherent.c,v 1.21.6.1 2003/11/15 23:26:38 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/bpf/net/bpf_filter.c,v 1.43.2.1 2003/11/15 23:26:49 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/bpf_image.c,v 1.25.2.1 2003/11/15 23:26:38 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/bpf_dump.c,v 1.13.2.1 2003/11/15 23:26:37 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.91.2.3 2003/11/21 10:20:46 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/pcap.c,v 1.63.2.6 2003/11/21 10:20:49 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.68.2.3 2003/11/19 18:13:48 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/savefile.c,v 1.92.2.8 2003/12/21 21:52:36 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/scanner.l,v 1.95.2.2 2003/12/16 05:20:44 guy Exp $ (LBL)
$Header: /tcpdump/master/libpcap/grammar.y,v 1.79.2.2 2003/12/16 05:20:44 guy Exp $ (LBL)


I also have
# /opt/gcc/bin/gcc -v
Reading specs from /opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.3/specs
gcc version 2.95.3 20010315 (release)

So I'm going to try that version...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

With 64 bit gcc:

# make clean
rm -f dnstop dnstop.o dnstop.core dnstop.c~
# export LPATH=/usr/local/lib
# make all
gcc -g -Wall -I/usr/local/include -I/usr/local/lib -c dnstop.c
dnstop.c: In function `StringCounter_report':
dnstop.c:751: warning: implicit declaration of function `getmaxy'
gcc -g -Wall -I/usr/local/include -I/usr/local/lib -o dnstop dnstop.o -lpcap -lcurses
/usr/local/lib/libpcap.sl: file not recognized: File format not recognized
collect2: ld returned 1 exit status
*** Error exit code 1

Stop.


With gcc 2.95:

# make clean
rm -f dnstop dnstop.o dnstop.core dnstop.c~
# make all
/opt/gcc/bin/gcc -g -Wall -I/usr/local/include -I/usr/local/lib -c dnstop.c
In file included from /usr/local/include/pcap.h:51,
from dnstop.c:16:
/opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.3/include/stdio.h:30: warning: `__va__list' redefined
/usr/include/sys/stdsyms.h:422: warning: this is the location of the previous definition
In file included from dnstop.c:19:
/opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.3/include/stdlib.h:28: warning: `__va__list' redefined
/opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.3/include/stdio.h:30: warning: this is the location of the previous definition
In file included from dnstop.c:27:
/opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.3/include/arpa/nameser.h:94: warning: `/*' within comment
In file included from dnstop.c:29:
/usr/include/sys/socket.h:484: parse error before `sendfile'
/usr/include/sys/socket.h:484: parse error before `bsize_t'
/usr/include/sys/socket.h:485: warning: data definition has no type or storage class
/usr/include/sys/socket.h:486: parse error before `sendpath'
/usr/include/sys/socket.h:486: parse error before `bsize_t'
/usr/include/sys/socket.h:487: warning: data definition has no type or storage class
In file included from /usr/include/sys/mp.h:55,
from /usr/include/sys/malloc.h:59,
from /usr/include/net/netmp.h:53,
from /usr/include/net/if.h:59,
from dnstop.c:31:
/usr/include/machine/sys/setjmp.h:45: redefinition of `struct label_t'
/usr/include/machine/sys/setjmp.h:59: warning: redefinition of `label_t'
/opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.3/include/sys/types.h:369: warning: `label_t' previously declared here
dnstop.c: In function `StringCounter_report':
dnstop.c:751: warning: implicit declaration of function `getmaxy'
*** Error exit code 1

Stop.


Sigh.......

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Ok - started over - removed my gcc 2.9.5 and installed:

http://hpux.ee.ualberta.ca/hppd/hpux/Gnu/gcc-3.3.2/

The Makefile is default except for CC=/usr/local/bin/gcc

# make clean
rm -f dnstop dnstop.o dnstop.core dnstop.c~

# make all
/usr/local/bin/gcc -g -Wall -c dnstop.c
In file included from dnstop.c:29:
/usr/include/sys/socket.h:484: parse error before "sendfile"
/usr/include/sys/socket.h:485: parse error before "bsize_t"
/usr/include/sys/socket.h:486: parse error before "sendpath"
/usr/include/sys/socket.h:487: parse error before "bsize_t"
In file included from /usr/include/sys/mp.h:55,
from /usr/include/sys/malloc.h:59,
from /usr/include/net/netmp.h:53,
from /usr/include/net/if.h:59,
from dnstop.c:31:
/usr/include/machine/sys/setjmp.h:45: redefinition of `struct label_t'
dnstop.c: In function `StringCounter_report':
dnstop.c:751: warning: implicit declaration of function `getmaxy'
*** Error exit code 1

Stop.


Any ideas?

Thanks...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Getting closer:

# make all
/usr/local/bin/gcc -g -Wall -c dnstop.c
In file included from dnstop.c:29:
/usr/include/sys/socket.h:484: parse error before "sendfile"
/usr/include/sys/socket.h:485: parse error before "bsize_t"
/usr/include/sys/socket.h:486: parse error before "sendpath"
/usr/include/sys/socket.h:487: parse error before "bsize_t"
dnstop.c: In function `StringCounter_report':
dnstop.c:751: warning: implicit declaration of function `getmaxy'
*** Error exit code 1

Stop.


Here's the function:
StringCounter_report(StringCounter * list, char *what)
{
StringCounter *sc;
int nlines = getmaxy(w) - 6;
printw("%-20s %9s %6s\n", what, "count", "%");
printw("%-20s %9s %6s\n",
"--------------------", "---------", "------");
for (sc = list; sc; sc = sc->next) {
printw("%-20.20s %9d %6.1f\n",
sc->s,
sc->count,
100.0 * sc->count / query_count_total);
if (0 == --nlines)
break;
}
}


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
A. Clay Stephenson
Acclaimed Contributor

Re: ld: cannot find -lpcap

I don't use the Gnu compilers but based upon your last error, I would say that you need to add
#include

to your source file or include it in a header file before socket.h. NOTE: some typedefs are controlled by #ifdef's so that you may need to assert some defines in your makefile.
If it ain't broke, I can fix that.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Thanks Clay - here's all the includes in dnstop.c:

#include
#include
#include

#include

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include
#include

#include
#include
#include

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
A. Clay Stephenson
Acclaimed Contributor

Re: ld: cannot find -lpcap

If you look in /usr/include/sys/socket.h at line 484 you will find a reference to a sbsize_t type. This is defined in /usr/include/sys/types.h. While this header file is included in your source file, the definition of sbsize_t or even the lack thereof is determined by some pre-processor #ifdef's and if defined()'s. You need to examine, sys/types.h to see which symbols you need to define and alter your makefile accordingly.
If it ain't broke, I can fix that.
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Okay - I give up - if anyone wants to take a crack at compiling dnstop, go for it. If successful, please post here how you did it.

Thanks...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
H.Merijn Brand (procura
Honored Contributor

Re: ld: cannot find -lpcap

10 minutes :)

where do you want to have it?

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Merijn Wow!

Did you use gcc or HP?

How about on your site?
http://www.cmve.net/~merijn/

Thanks...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
H.Merijn Brand (procura
Honored Contributor
Solution

Re: ld: cannot find -lpcap

I used gcc, because that's what the Makefile said :)

--8<-- Makefile
CFLAGS=-g -Wall -I/usr/local/include -I/pro/local/include
PROG=dnstop
DATE != date +%Y%m%d
CC=gcc

SRCS= $(PROG).c \
known_tlds.h

# You may need to uncomment this, esp on Solaris
XTRALIBS= # -lnsl -lresolv -lsocket

all: $(PROG)

$(PROG): $(PROG).o
$(CC) $(CFLAGS) -o $@ $(PROG).o -static -L/usr/local/lib -L/pro/local/lib -lpcap -lncurses $(XTRALIBS)

clean:
rm -f $(PROG) $(PROG).o $(PROG).core $(PROG).c~

tar:
mkdir $(PROG)-$(DATE)
cp -p LICENSE CHANGES $(SRCS) dnstop.8 Makefile $(PROG)-$(DATE)
tar czvf $(PROG)-$(DATE).tar.gz $(PROG)-$(DATE)
chmod 444 $(PROG)-$(DATE).tar.gz
rm -rf $(PROG)-$(DATE)
-->8---

I added two include directories to CFLAGS (-I...)
I added to lib search path's to ld (-L...)
I added -statc to load, so I don't have to supply libpcap.sl and libncurses.sl

I changed #include to #include and -lcurses to -lncurses because curses doesn't know about getmaxy ()

http://www.cmve.net/~merijn/dnstop-20040309-pa2.0

Enjoy. Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: ld: cannot find -lpcap

Phrrrt. writing these posts took longer than building the stuff :]

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Thanks Merijn!

I'd still like to compile myself - almost got it working...did the same as you....had to add:

#ifndef _BSIZE32_T
# define _BSIZE32_T
typedef int32_t sbsize32_t;
typedef uint32_t bsize32_t;
#endif
#ifndef _BSIZE64_T
# define _BSIZE64_T
# if !defined(__STDC_32_MODE__)
typedef int64_t sbsize64_t;
typedef uint64_t bsize64_t;
# endif
#endif
#ifndef _BSIZE_T
# define _BSIZE_T
# if defined(_APP32_64BIT_OFF_T) || defined(_KERNEL)
typedef int64_t sbsize_t;
typedef uint64_t bsize_t;
# else
typedef long sbsize_t;
typedef unsigned long bsize_t;
# endif
#endif

To bottom of /usr/local/lib/gcc-lib/hppa2.0n-hp-hpux11.00/3.2/include/sys/types.h before the last #endif

Now I get:

# gmake all
/usr/local/bin/gcc -g -Wall -I/usr/local/include -c -o dnstop.o dnstop.c
cc1: warning: changing search order for system directory "/usr/local/include"
cc1: warning: as it has already been specified as a non-system directory
/usr/local/bin/gcc -g -Wall -I/usr/local/include -o dnstop dnstop.o -static -L/usr/local/lib -lpcap -lncurses
/usr/ccs/bin/ld: Unsatisfied symbols:
shl_load (first referenced in /usr/lib/libc.a(nss_deffinder.o)) (code)
shl_findsym (first referenced in /usr/lib/libc.a(nss_deffinder.o)) (code)
collect2: ld returned 1 exit status
gmake: *** [dnstop] Error 1


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
H.Merijn Brand (procura
Honored Contributor

Re: ld: cannot find -lpcap

add -lc_r or -ldld

these symbols are in /usr/lib/dld.sl, libdld.sl, and libc_r.sl (the reentrant version of libc)

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Geoff Wild
Honored Contributor

Re: ld: cannot find -lpcap

Merijn - done!

Had to do it like this:

CFLAGS=-g -Wall -l:libdld.sl -I/usr/local/include

Otherwise I got
/usr/bin/ld: Can't find library: "dld"

Thanks for all your help.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.