在linux上,我试图创建一个共享库libbar.so,该库嵌入了一个商业静态库(许可就可以了).商业库具有4个版本:libfoo-seq.a,libfoo-mt.a,libfoo-seq.so和libfoo-mt.so(它们都提供相同的符号,只是代码是顺序/多线程的,并且该库是静态/共享的).在这四个文件中,我希望我的代码始终使用顺序的foo库,因此在创建libbar.so时,我将目标文件和libfoo-seq.a链接在一起.
On linux I am trying to create a shared library, libbar.so, that embeds a commercial static library (licensing is fine). The commercial library has 4 versions: libfoo-seq.a, libfoo-mt.a, libfoo-seq.so, and libfoo-mt.so (they all provide the same symbols, just the code is sequential/multi-threaded, and the lib is static/shared). Of these four I want my code always to use the sequential foo library, so when I create libbar.so I link together my object files and libfoo-seq.a.
问题是我的库用户可能在他们拉进我的libbar.so时就已经拉进了libfoo-mt.so,因此,在读入libbar.so时,libfoo中的所有符号都已经存在,因此我对foo中的函数的调用被解析为多线程版本.
The problem is that the users of my library may have already pulled in libfoo-mt.so by the time they pull in my libbar.so, thus all symbols from libfoo are already present by the time libbar.so is read in, so my calls to the functions in foo are resolved to the multithreaded version.
我想知道如何解决此问题?在编译以创建目标文件以及将目标文件与libfoo-seq.a链接以创建libbar.so时,我需要使用哪种魔术标记?
I wonder how can I resolve this issue? What kind of magic flags do I need to use when I compile to create my object files and when I link my object files with libfoo-seq.a to create libbar.so?
推荐答案您可以通过版本脚本在libbar中隐藏libfoo的符号:
You can hide libfoo's symbols in libbar via version script:
$ cat libbar.map { global: libbar_*; local: libfoo_*; }; $ gcc ... -o libbar.so -Wl,--version-script=libbar.map更多推荐
如何将静态库嵌入共享库?
发布评论