When is the gcc flag -nostartfiles used?

You'd use -nostartfiles (and -nostdlib) when you do not want any standard libraries (like libc and libgcc) to be linked in and standard initialization actions, like calling C++ constructors, to be run. Typical use-cases are writing system software like kernels or firmwares.


I think that with -nostartfiles command line arguments will not be passed to main() and environment variables will not be available to the executable, among other things. Docker uses -nostartfiles in an example where a single binary is run within a simple container, i.e., where the container is run like a single binary: https://docs.docker.com/develop/develop-images/baseimages/, so that is another use case.

Slightly related is Source for 'startup files' in gcc/mingw, which lists functions that are linked into to the code if -nostartfiles option is not used.

Tags:

Gcc