tcpdump mailing list archives

Re: Cannot find -lpcap when statically compiling a C project


From: liu wen <caonimagongling () gmail com>
Date: Fri, 20 Nov 2015 01:35:12 +0100

On Fri, Nov 20, 2015 at 12:52 AM, Guy Harris <guy () alum mit edu> wrote:


On Nov 19, 2015, at 3:29 PM, liu wen <caonimagongling () gmail com> wrote:

I want to statically compile a C project in a laptop(fedora), using
command
line like:

gcc -o myprogram -static main.c ... -levent -lpcap

but I get error:

/usr/bin/ld: cannot find -lpcap
/usr/bin/ld: cannot find -lc

I tried to locate libpcap.a and find no such a file

See if there are libpcap RPMs that you haven't installed, perhaps one with
a name like "libpcap-dev" or something with "-dev" in the name, although
usually "-dev" packages include both static libraries and header files, so
without the "-dev" package you won't be able to compile anything.  Perhaps
Fedora has separate packages for the libpcap runtime (shared libraries),
libpcap development (headers), and libpcap static libraries.


# locate libpcap-dev
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/changed_by
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/checksum_data
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/checksum_type
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/command_line
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/from_repo
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/from_repo_revision
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/from_repo_timestamp
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/installed_by
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/reason
/var/lib/yum/yumdb/l/75ed44a0adeee36906852424e93dafd3a950ae77-libpcap-devel-1.3.0-2.fc18-x86_64/releasever

what commands/steps should I follow so as to get the libpcap.a?



However, "cannot find -lc" means it also doesn't have a static version of
libc, so you'll also have to find a Fedora package with a static version of
libc.



how can I find a static version of libc?




if I compile dynamically, it successfully produces an executable

ldd relay
linux-vdso.so.1 => (0x00007fff4bfaf000)
libevent-1.4.so.2 => /lib/libevent-1.4.so.2 (0x00007f14053a5000)
libpcap.so.1 => /lib64/libpcap.so.1 (0x00000035b4a00000)
libc.so.6 => /lib64/libc.so.6 (0x00000035b0a00000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00000035cea00000)
librt.so.1 => /lib64/librt.so.1 (0x00000035b1a00000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00000035b2e00000)
/lib64/ld-linux-x86-64.so.2 (0x00000035b0200000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000035b1600000)


This executable only works in this laptop.

Probably because either

        1) the other laptops are running the same version of Fedora but
don't have all those shared libraries installed

or

        2) they're running some other OS, so that the libraries have
different pathnames.

As far as I know, there's not much binary compatibility between different
Linux distributions for anything other than programs with no dynamic
libraries; there *might* be some level of binary compatibility allowing
software compiled for older versions of a distribution to run on newer
versions.

If I compile the project in
other laptops, it doesn't work properly(the libpcap can't capture all
packets successfully, I don't know why).

I.e., if you compile it on another machine, it doesn't even work on *that*
machine?


yes, if I compile it on the other machine, it still doesn't work (it
doesn't capture all passing-by packets on that machine)


What does "tcpdump -h" print on the laptop where the build works and on
the laptops where it doesn't?


it doesn't works on laptop of

tcpdump version 4.5.1
libpcap version 1.5.3


it works on laptop of

tcpdump version 4.3.0
libpcap version 1.3.0
_______________________________________________
tcpdump-workers mailing list
tcpdump-workers () lists tcpdump org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers


Current thread: