简体   繁体   English

具有静态链接依赖项的共享库

[英]Shared library with statically linked dependencies

I just wanted to understand how shared libraries with statically linked libraries are expected to perform.我只是想了解具有静态链接库的共享库如何执行。 I am writing a shared library ( lshared.so ) that is statically linked to another library ( lstatic ).我正在编写一个静态链接到另一个库( lstatic )的共享库( lshared.so Now, I have another executable helloworld which loads a dynamic version of library lstatic (lstatic.so) and lshared.so as well.现在,我有另一个可执行的helloworld ,它也加载了库lstatic (lstatic.so) 和lshared.so的动态版本。 Will the static version of library (lstatic) loaded by lshared.so and the dynamic version (lstatic.so) conflict. lshared.so加载的static版本库(lstatic)和动态版本(lstatic.so)会不会冲突。 Will they share any global state.他们会共享任何全球 state。 Tried to show it better below.试图在下面更好地展示它。

helloworld
     --> lshared.so (statically linked to lstatic at compile time)
     --> lstatic.so (hello world loads this at runtime)

To throw some context, I've to use a shared library for logging.为了抛出一些上下文,我必须使用共享库进行日志记录。 It is possible that lshared.so is statically linked to a different version that the one available to helloworld at runtime. lshared.so 有可能静态链接到与运行时 helloworld 可用的不同版本。

Will the static version of library (lstatic) loaded by lshared.so and the dynamic version (lstatic.so) conflict. lshared.so加载的static版本库(lstatic)和动态版本(lstatic.so)会不会冲突。

Possibly.可能。

Will they share any global state.他们会共享任何全球 state。

Possibly.可能。

The answers depend on how exactly lshared.so is built (which symbols it exports), and how the main helloworld binary is linked.答案取决于lshared.so的构建方式(它lshared.so的符号)以及主helloworld二进制文件的链接方式。

The answers also tend to be somewhat complicated, and may depend on inlining and other optimizations, and possibly on compiler versions.答案也往往有些复杂,可能取决于内联和其他优化,也可能取决于编译器版本。

It is best to avoid doing that by using shared version of lstatic.so , where all the answers become simple.最好通过使用lstatic.so的共享版本来避免这样做,所有答案都变得简单。

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

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