简体   繁体   English

具有共享库的C ++静态库链接。 编译会好吗?

[英]C++ static library link with shared lib. Compiling would be fine?

Here is a C++ project, and its lib dependency is 这是一个C ++项目,其lib依赖项是

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

Hello.exe depends on Ba and A.so, and Ba depends on A.so. Hello.exe取决于Ba和A.so,Ba取决于A.so。 GCC compiler will link Hello.exe successful? GCC编译器将链接Hello.exe成功吗?

And if there is a b.cc file in Ba which includes a header file ah of A.so, and also uses some interfaces of A.so, then with right "include" path setting, compiling b.cc to bo should be successful. 并且,如果Ba中有一个b.cc文件,其中包括A.so的头文件ah,并且还使用了A.so的某些接口,则通过正确的“ include”路径设置,将b.cc编译为bo应该成功。 But if without A.so as input, the link of Ba would be failed, right? 但是,如果没有A.so作为输入,Ba的链接将会失败,对吗?

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. 谢谢。

A static library is just a collection of object files created from compiled .c/.cpp files. 静态库只是从编译的.c / .cpp文件创建的目标文件的集合。 It cannot have link relationships. 它不能具有链接关系。

You will need to specify link dependencies to both A.so and Ba when you compile Hello.exe 编译Hello.exe时,需要同时指定A.so和Ba的链接依赖关系

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 附带说明,您应该将A.so重命名为libA.so,而是

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 直接与示例1链接到A.so将要求A.so始终与Hello.exe在同一目录中

If you use example 2, you can put libA.so anywhere and use LD_LIBRARY_PATH to point to the right directory. 如果使用示例2,则可以将libA.so放在任何位置,然后使用LD_LIBRARY_PATH指向正确的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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