7 ms·
You cant statically compile in glibc right?
by dman 7y ago
You cant statically compile in glibc right?
- spatulon 7y agosure you can: $ cat hello.c #include <stdio.h> int main() { printf("hello world!\n"); } $ gcc -o hello hello.c $ ldd hello linux-vdso.so.1 (0x00007ffff9da0000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fed449d0000) /lib64/ld-linux-x86-64.so.2 (0x00007fed45000000) $ gcc -o hello hello.c -static $ ldd hello not a dynamic executable
- luizfelberti 7y agoI don't think the parent comment's point was if this was technically possible. glibc is GPL licensed, and the GPL explicitly forbids statically linking to it unless your code is GPL too. Thus any non-GPL project has it's license tainted by the GPL if you statically link it. It's not a technical limitation, it's a legal one.
- cesarb 7y agoThis is false. The license for glibc is the LGPL, not the GPL, and the LGPL has an exception to allow static linking without the whole code having to be under the LGPL, as long as the .o files are also distributed to allow linking with a modified glibc ("As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice [...] and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library.")
- luizfelberti 7y agoSounds like I got conned by my (poor) memory. I should have re-googled this before posting, thanks for the correction.
- jfkebwjsbx 7y agoYes, but for many projects it means no static linking in practice.
- freemint 7y agoI might be uneducated but wasn't there a "system library exception" or something like that in GPL to prevent these problems?
- yarrel 7y agoThis isn't a legal limitation. It's FUD. See here - https://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynamic https://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynami...
- luizfelberti 7y agoThanks for the link, that's very useful. I should have re-googled this stuff instead of commenting "from memory", sorry for spreading the FUD :/
- a1369209993 7y agoAlso, right above that: https://www.gnu.org/licenses/gpl-faq.html#GPLStaticVsDynamic https://www.gnu.org/licenses/gpl-faq.html#GPLStaticVsDynamic Dynamically linking a GPL library is the same as statically linking a GPL library; the resulting executable must be GPL-licensed.
- sandov 7y agoThat's also a good reason to avoid glibc and switch to a musl-based system.
- saagarjha 7y agoYou can, but it is not supported. Certain features (NSS, iconv) will not work.
- otabdeveloper2 7y ago> Certain features (NSS, iconv) will not work. If you're the kind of person who wants static linking then you really don't want these features. The real problem is that statically linked programs under Linux don't (didn't?) support VDSO, which means that syscalls like gettimeofday() are suddenly orders of magnitude slower. In the end, we had to do a kind of pseudo-static linking - link everything static except glibc.
- saagarjha 7y agoI think the vDSO page is mapped into every process regardless of how the program is linked, although you may have difficulty using it.
- justincormack 7y agoVdso is supported with static linking in Musl libc at least.