Why should I use gcc to link my application?

Question

Why should I use the compiler, gcc, to link my application, rather than using the ld command directly?

Answer

When you use the gcc command to link your application, it invokes the ld command for you, but passes additional flags and command-line arguments to the linker. For example, gcc adds appropriate options to tell the linker to link against the required C or C++ language support libraries by default. It uses the command-line options for the gcc command to select the appropriate set of libraries for your program, such as matching based on the target CPU, ISA encoding, or floating-point options.

If you choose to link the application directly with ld instead, you must specify everything needed to link your application. Using the linker directly requires detailed knowledge of the libraries required to produce the application.

CodeSourcery recommends you use gcc to link your application.


This entry was last updated on 12 May 2010.