tags:

views:

92

answers:

1

Here is a C++ project, and its lib dependency is

Hello.exe 
   -> A.so 
   -> B.a
B.a 
  -> A.so

Hello.exe depends on B.a and A.so, and B.a depends on A.so. GCC compiler will link Hello.exe successful?

And if there is a b.cc file in B.a which includes a header file a.h of A.so, and also uses some interfaces of A.so, then with right "include" path setting, compiling b.cc to b.o should be successful. But if without A.so as input, the link of B.a would be failed, right?

gcc -c b.cc -I../A/include ;; successful 

gcc -a B.a b.o             ;; fail

Where I can find detail library link documents about these complex reference relationship ...

Thanks.

+1  A: 

A static library is just a collection of object files created from compiled .c/.cpp files. It cannot have link relationships.

You will need to specify link dependencies to both A.so and B.a when you compile Hello.exe

off the top of my head it would be something like

gcc -o Hello.exe B.a A.so

As a side note you should rename A.so to libA.so and instead do

gcc -o Hello.exe -lA B.a

Linking to A.so directly like example 1 will require that A.so is always in the same directory as Hello.exe

If you use example 2, you can put libA.so anywhere and use LD_LIBRARY_PATH to point to the right directory.

Charles