Frage

I've already take a look on ALL answers in stackoverflow: no way.

I've compiled a shared library A that use Nite1.3. So my library is in:

 /usr/local/lib/A.so

I've my project B that include A.

Compiling B, I get a lot of undefined reference to.. how can I really solve the problem?

usr/local/lib/A.so: undefined reference to `XnVFlowRouter::XnVFlowRouter(char const*)'
.....
War es hilfreich?

Lösung

What's happening is that A.so doesn't know that the nite symbols are obtainable from the libnite.so, so when it tries to resolve the symbols it doesn't know to look in that library, and nothing in the environment tells it to load that library to go looking for symbols.

Two solutions:

(1) Recompile A.so with an explicit dependency on Nite 1.3, so when compiling you do:

g++ -o A.so <files making up A.so> -L<DIRECTORY OF NITE> -Wl,-rpath <DIRECTORY OF NITE> -lnite

If libnite.so is located in one of the standard locations, then you should be able to omit the -L and -Wl,-rpath options. This will make your library depend on libnite explictly.

(2) link to libnite.so when compiling B, so the link line should add:

-L<DIRECTORY OF NITE> -Wl,-rpath <DIRECTORY OF NITE> -lnite

As an addenda, if you have the .h files, but don't have a corresponding .a or .so for the implementation then you will need to address that issue before you are able to use A.so.

as an e.g., if libnite.so is in /usr/local/lib, then you would need to add:

-L/usr/local/lib -Wl,-rpath /usr/local/lib -lnite

to the compile line so that it knows where to look for the library at compile time (the -L option), and at run-time (the -Wl,-rpath option).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top