我可以建立通过链接静态库的共享库?

我可以建立通过链接静态库的共享库?

问题描述:

我有一堆的静态库(* .a)中,我想建立一个共享库(* .a)中,以对那些静态链接库(* .a)中。我怎样才能在gcc / g ++的这样做呢?谢谢!

I have a bunch of static libraries (*.a), and I want to build a shared library (*.a) to link against those static libraries (*.a). How can I do so in gcc/g++? Thanks!

您可以(只提取所有的.o 文件和将它们链接-shared 的.so ),但无论它的工作原理,以及它如何工作的,取决于平台以及是否静态库是编译成的与位置无关的code 的(PIC)。在某些平台上(如x86_64的),非PIC code不是共享库中有效,将无法正常工作(其实我觉得连接器将拒绝让的.so )。在其他平台上,非PIC code将在共享库中工作,但使用它,甚至不同的同一程序的实例库的内存副本是不是不同程序之间共享,所以它会造成巨大的内存膨胀。

You can (just extract all the .o files and link them with -shared to make a .so), but whether it works, and how well it works, depends on the platform and whether the static library was compiled as position-independent code (PIC). On some platforms (e.g. x86_64), non-PIC code is not valid in shared libraries and will not work (actually I think the linker will refuse to make the .so). On other platforms, non-PIC code will work in shared libraries, but the in-memory copy of the library is not sharable between different programs using it or even different instances of the same program, so it will result in HUGE memory bloat.