简体   繁体   中英

Linking with .so in g++ results in undefined references

To keep this simple... assume I have the following: A.lib, libB.so (which uses A.lib), and C.exe (which uses libB.so). Note: This is Linux, not Windows. I'm just using .exe to convey binary type/purpose.

I'm just trying to compile and link C.exe form the command prompt as it's just a simple test program. This is the line I'm using:

g++ -I../include C.cpp -o C.exe -L../lib -lB

The result is many undefined references to things that would be found in A.lib. There are no errors referencing anything exported from libB.so.

If I copy libB.so to that same directory and use this command:

g++ -I../include C.cpp -o C.exe -lB

The result is C.exe is built and can be run without error.

Once libB.so is build I shouldn't need the libs that were used to build it. Despite this, I thought I would try something as a final attempt. I copied A.lib into the same lib directory as libB.so and tried the original build command again. The result was the same.

Any and all thoughts appreciated.

SamVershavchik put me on the path to the answer. I tried this command first:

g++ -I../include C.cpp -o C.exe -Wl,-R,../lib -lB

The result was a clean build but another error about missing symbols when I ran C.exe.

I modified the command to the following:

g++ -I../include C.cpp -o C.exe -Wl,-R,--just-symbols=../lib/libB.so -lB

This resulted in a clean build and the ability to run C.exe without error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM