Compile a shared object (.so) with static glibc

I am creating code that should be a shared object (.so).

The problem is that libc on my construction machine may be newer than published machines, so I want to link it statically to avoid compatibility issues. (My program uses memcpy, which apparently is GLIBC_2.14 when it can reach 2.5).

Compiling with -shared and -static does not work, since crtbeginT.o was not compiled with -fPIC.

Edit: maybe this is not a duplicate of GCC linking libc static and some other library dynamically being reviewed? , since this question suggests that the main elf binds libc statically, and this is about a shared object that binds libc statically.

+4
source share
1 answer

You want to statically link glibc in your shared library.

You must not do this.

If you try, you will have the right to violate the C ++ One Definition Rule (ODR) rules. This is because some parts of glibc will be from the "old" version of your target machine, and some will be from the "new" version of your library. The result is undefined behavior.

: glibc (, ). , glibc ( glibc). , glibc, , .

memcpy , . fooobar.com/questions/154960/... - : fooobar.com/questions/98585/...

+7

Source: https://habr.com/ru/post/1672165/


All Articles