Question

I have developed a shared library B.so, which depends on A.so. When I write a program test.exe using B.so, but there is a compile error, it said that some symbols(the symbols are in A.so) not found. My build line:

gcc test.c -o test.exe -fPIC -I./ -L./ -lB

Do we have a method that, how to build test.exe successfully,but not link A.so.

Était-ce utile?

La solution

how to build test.exe successfully,but not link A.so.

There are at least two method:

  1. export a proper LD_LIBRARY_PATH

    export LD_LIBRARY_PATH=/path/to/A
    gcc ... -lB
    
  2. using ld option -rpath (discovered by the asker @iceKing himself)

    gcc -Wl,-rpath=/path/to/A ...
    

In both case, ld will automatically search for libraries depended by these libraries list explicitly.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top