简体   繁体   English

共享库中静态库中的静态函数

[英]Static functions in a static lib in a shared object

I have an application that uses shared objects ( *.so ) as plugins which are loaded at run time. 我有一个使用共享库( *.so )作为在运行时加载的插件的应用程序。 I also have a static library ( *.a ) which contains a few static functions.If both PluginA and PluginB link to the library, will they get their own copies of the static functions as well? 我还有一个静态库( *.a ),其中包含一些静态函数,如果PluginA和PluginB都链接到该库,它们也会得到自己的静态函数副本吗?

Yes, both plugins will get their own copies of function/symbols contained in the static .a library. 是的,两个插件都将获得它们自己的包含在静态.a库中的功能/符号副本。 For use in shared libraries or plugins the .a library must be position independent code, which can be achieved with the option -fPIC at compilation and link time. 要在共享库或插件中使用,.a库必须是与位置无关的代码,可以在编译和链接时使用选项-fPIC来实现。

You must also make sure that PluginA and PluginB are not dlopened() with the option RTLD_GLOBAL as there could be nameclashes between the two copies of the static library contained in PluginA and PluginB. 您还必须确保使用选项RTLD_GLOBAL不会将PluginA和PluginB设置为dlopened(),因为PluginA和PluginB中包含的静态库的两个副本之间可能存在名称冲突。 This problem of nameclashes becomes even more pronounced in shared libraries if you were to link PluginA and PluginB dynamically at compile time. 如果要在编译时动态链接PluginA和PluginB,则名称冲突的问题在共享库中更加明显。

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

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