cgcclinkerld

Linking troubles in C


I have a test.c that is using code from two libraries. One is statically linked (say libstatic.a, the other - dynamically (e.g. libdynamic.so).

I compiled my c file as follows:

gcc -I../inc -c test_subframeip_omap.c -o test_subframeip_omap.o

How do I link now the static and dynamic libraries in order to produce the final executable?


Solution

  • You generally need something like:

    gcc -I../inc -c test_subframeip_omap.c -o test_subframeip_omap.o
    gcc -L/path/to/libs -l static -ldynamic -o test_subframeip_omap test_subframeip_omap.o
    

    The -L adds directories to the library search path and -l specifies a library to link with. It's also done as part of the link, not the compile.