ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
However, it is possible, as the kernel and libc can be compiled, right?
But is is difficult. Even with this program:
Code:
int main()
{
return 0;
}
if you compile it the normal way, say "gcc -o donothing donothing.c", then it gets linked with libc. You can check this with "ldd donothing".
There are command line options to gcc for not-linking in the standard libs. (check man gcc for -nostdlib or -nodefaultlibs). But I tried it, and it's not that easy. When you compile with (one of) these options, gcc doesn't even know how to get the program started anymore...
Distribution: Gentoo for me, Slackware for servers
Posts: 27
Rep:
I don't know if you already know this but here it is :
libc isn't neccesary, it's necesary at compile time, cause it has the info that is needed by the program to 'do things'.
If I do a:
printf("Hi\n");
The way of do that printf in 'computer languaje' is stored in glibc. But when I'm making a binary of that you can choise if you want to make it to search on the libc (glibc, culibc, etc) or store it in the binary itself.
Making a big binary, with all the instructions inside, its called static.
Making a small binary, that has the direction of where are the instructions (glibc) is called shared.
The pros and cons: When using a static binary you don't need anything else. But the functions inside it, the store 'ways of do things' inside, are never gonna be actualized. Also the binary use to be to mouch big in filesize. The shared way (the stantard of the distros for distribute binarys) need some run time dependencis, glibc basic, mostly, if it needs other lib, like libpng for example, libpng also is gonna to need glibc.
But note that static linking can open a security hole. When a bug / security hole is discovered in a library, you can update the library to close the hole, but static linked binaries will still use there own statically linked version, including the hole.
Also, not only the size of the executable increases when linked statically, but also the memory footprint when it runs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.