In a project, my colleague create a static library, e.g liba.a, which linked with app.
在一个项目中,我的同事创建了一个静态库e。g仙女镇李坝社区。a与app相连。
In liba.a he overwrites the libc malloc() to his owner version.
仙女镇李坝社区。a他重写了libc malloc()到他的所有者版本。
I create a shared library libs.so which also linked with app.
我创建了一个共享库libs。这也与应用程序有关。
The problem is when my libs.so linked with app, the malloc() used in my libs.so will be the one in liba.a, not the one in standard libc.so, this causes problems.
问题是当我撒谎的时候。所以连接到app, malloc()在我的libs中使用。那就是liba里的那个。a,不是标准libc中的那个。所以,这也引起了一些问题。
Then, I want static link the libc.a to my libs.so, I used -static -shared -fPIC flags for gcc.
然后,我想要静态链接的libc。我填词。因此,我为gcc使用了-static -shared -fPIC标志。
But I always get arm-2012.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.3/../../../../arm-none-linux-gnueabi/bin/ld: arm-2012.03/bin/../arm-none-linux-gnueabi/libc/usr/lib/libc.a(dl-tsd.o)(.text+0x14): R_ARM_TLS_LE32 relocation not permitted in shared object.
但我总是手臂- 2012.03 / bin / . . / lib / gcc / arm-none-linux-gnueabi / 4.6.3 / . . / . . / . . / . ./arm-none-linux-gnueabi/bin/ld: arm-2012.03/bin/.. ./arm-none-linux-gnueabi/libc/usr/lib/libc.a(.text+0x14):
Does anyone have idea about it?
有人知道吗?
Thanks forward.
谢谢。
1 个解决方案
#1
2
You can't, because code that goes in shared library must be compiled with -fPIC
and code in static libraries isn't. If you managed to do it, the resulting executable would end up linked with libc multiple times, which would be really fragile anyway and probably crash sooner or later, so you shouldn't do it anyway. Therefore:
不能,因为共享库中的代码必须用-fPIC编译,静态库中的代码则不行。如果您成功地做到了,那么结果可执行文件将被多次链接到libc中,无论如何,这将是非常脆弱的,并且可能迟早会崩溃,所以您不应该这样做。因此:
Don't. Dynamic libraries have to link against system libraries dynamically and any executable that links against any dynamic libraries also has to link system libraries dynamically.
不喜欢。动态库必须动态链接系统库,任何与动态库相关联的可执行文件都必须动态链接系统库。
I would also like to remind you, that linking GNU libc against non-GPL application statically is illegal, since LGPL only excepts dynamically linked code. This is on purpose to allow bugfixing the library without recompiling the executable for which source may not be available. It's rather common in Linux to upgrade shared libraries with bugfixed version without recompiling dependent executables; libc developers know how to do that.
我还想提醒您,静态地将GNU libc链接到非gpl应用程序是非法的,因为LGPL只包括动态链接的代码。这是为了允许在不重新编译源不可用的可执行文件的情况下对库进行错误处理。在Linux中,使用错误版本升级共享库而不重新编译依赖的可执行文件是很常见的;libc开发人员知道如何做到这一点。
#1
2
You can't, because code that goes in shared library must be compiled with -fPIC
and code in static libraries isn't. If you managed to do it, the resulting executable would end up linked with libc multiple times, which would be really fragile anyway and probably crash sooner or later, so you shouldn't do it anyway. Therefore:
不能,因为共享库中的代码必须用-fPIC编译,静态库中的代码则不行。如果您成功地做到了,那么结果可执行文件将被多次链接到libc中,无论如何,这将是非常脆弱的,并且可能迟早会崩溃,所以您不应该这样做。因此:
Don't. Dynamic libraries have to link against system libraries dynamically and any executable that links against any dynamic libraries also has to link system libraries dynamically.
不喜欢。动态库必须动态链接系统库,任何与动态库相关联的可执行文件都必须动态链接系统库。
I would also like to remind you, that linking GNU libc against non-GPL application statically is illegal, since LGPL only excepts dynamically linked code. This is on purpose to allow bugfixing the library without recompiling the executable for which source may not be available. It's rather common in Linux to upgrade shared libraries with bugfixed version without recompiling dependent executables; libc developers know how to do that.
我还想提醒您,静态地将GNU libc链接到非gpl应用程序是非法的,因为LGPL只包括动态链接的代码。这是为了允许在不重新编译源不可用的可执行文件的情况下对库进行错误处理。在Linux中,使用错误版本升级共享库而不重新编译依赖的可执行文件是很常见的;libc开发人员知道如何做到这一点。