This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Link to libpcap shared object

I'm attempting to compile a .c file on a Sitara Am335x starter kit with sdk-linux-amr335-evm-02.00.01.07 and require libpcap.

I haven't had luck with installing the latest libpcap (incompatible lex and issues with flex/bison). However, I see that there is a libpcap.so in the /usr/lib directory supplied with the SDK rootfs. I went ahead and added the headers from the libpcap package to the /usr/include directory.

I have attempted to compile with gcc foo.c -o foo -lpcap and gcc -L/usr/lib -o foo foo.c -lpcap and get the same error:

"/user/lib/gcc/arm-Linux/gnueabi/4.9.3/../../../../arm-Linux-gnueabi/bin/ld: cannot find -lpcap

collect2: error: ld returned 1 exit status"

libpcap.so.1 and libpcap.so.1.6.2 are clearly located in /usr/lib so I don't understand why it can't find the file?

It has occurred to me that the error may be in the gcc target but I don't know how to change that or add the library to the target?

Also, I'm currently hosting the kernel and rootfs on an SD card as I need both eth0 and eth1 configured into a bridge. Consequently, I've been attempting to compile everything on the board itself. Is this something that has to be cross compiled and then moved to the SD card?

  • Hello Seeley,

    Could you run ldconfig to configure dynamic linker run-time bindings then try again.

    Best regards,
    Kemal

  • I'm not 100% sure what you mean by "run ldconfig to configure..." but I have verified that ldconfig -p includes libpcap.so.1 and /etc/ld.so.conf points to the /lib and /usr/lib directories. The problem seems to be with GCC not accessing the shared library cache. Is there a way to change the cache that GCC searches?
  • When building the executable with gcc foo.c -o foo -lpcap -v I get the library path:

    LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabi/4.9.3/:/usr/lib/gcc/gcc/arm-linux-gnueabi/4.9.3/../../../:/lib/:/usr/lib/

    Which seems to say that GCC should be including /usr/lib in the library path but it can't seem to find any of the libraries within that directory.
  • So, I still have no idea why the local gcc on the starter kit was incapable of using the shared object file provided by the SDK in /usr/lib. That being said, the problem can be fixed by building your own cache in /usr/local/lib and building necessary libraries one at a time.

    For anyone attempting to use the libpcap on the Sitara Starter Kit, you'll need to install m4, bison and flex (in that order!) and be sure to add /usr/local/bison/bin to your $PATH with "export PATH=/usr/local/bison/bin:$PATH" (same way you added m4 to your path after installing it) before running configure in the libpcap package. You'll also need to add /usr/local/lib to your ld.so.conf file so that gcc searches your new shared object cache.
  • Thank you for the contribution.