On Nov 19, 2015, at 3:29 PM, liu wen <caonimagongl...@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. 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. > 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? What does "tcpdump -h" print on the laptop where the build works and on the laptops where it doesn't? _______________________________________________ tcpdump-workers mailing list tcpdump-workers@lists.tcpdump.org https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers