If I call the GCC Linker with the option -nostdlib
does this override any manual/explicit appendecis of standardlibs?
GCC is 4.8.1 from MinGW.
Example:
gcc -nostdlib [MyObjectsAndLibraries] -lmsvcrt -o Outfile
Since libmsvcrt
is a standard library, will it be added to the link process or will it be ignored? I can't find any reliable data on this., this is why I would also appreciate some kind of source to this.
In this context, "standard libraries" means the libraries that gcc
would implicitely link by default. Libraries explicitely mentioned on the command line will always be linked. In fact, gcc
documentation at http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Link-Options.html#Link-Options even points out that unless you really know what you're doing you should add explicitely -lgcc
when using -nostdlib
, as the compiler may rely on some builtins defined in it:
In other words, when you specify -nostdlib or -nodefaultlibs you should usually specify -lgcc as well. This ensures that you have no unresolved references to internal GCC library subroutines.
Since I found this on Google, it is important to note the order of which you specify things. @Virgile's answer is enough, but you may run into linker errors when you link. So with your build, it may be problematic because your exe never gets linked with msvcrt or gcc.
Here is a canonical build statement that expands on @Virgile's asnwer
gcc -g0 -O2 -Wall -nostdlib -c *.o -o a.exe -lmsvcrt -lgcc
Here is a good reference
https://stackoverflow.com/a/18389266/2262111