MinGW Parameters Linker

 

- Info:

- This tutorial show gcc command line options which control linking.

- This tutorial is based on http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options

 

- -l:

- Defines which library to use when linking without using their extensions .lib or .dll:

gcc Test1.o -lMyLibrary Test2.o

- In the above example MyLibrary.lib is searched only after Test1.o has already been linked.

 

- -L:

- Add directory to the list of directories to be searched when looking for libraries inluded using option -l:

gcc -L. -LD:\MyLibraries -lMyLib Test.o

- Using '.' after -L means to search in current directory.

 

- -nostartfiles:

- Do not use standard system startup files when linking.

gcc Test.o -nostartfiles

 

- -nodefaultlibs:

- Do not use standard system libraries when linking.

gcc Test.o -nodefaultlibs

 

- -nostdlib:

- Do not use standard system startup files and libraries when linking.

gcc Test.o -nostdlib

gcc Test.o -nostartfiles -nodefaultlibs

 

- -static:

- Prevents linking with dynamic shared libraries like DLL:

gcc Test.o -static

 

- -shared:

- Produce dynamic shared library like DLL:

gcc -shared Test.o -o Test.dll