GCC uses a separate linker program (called ld.exe ) to perform the linking.
Linker command files allow you to put linker options and directives in a file; this is useful when you invoke the linker often with the same options and directives. Linker command files are also useful because they allow you to use the MEMORY and SECTIONS directives to customize your application.
The -l option tells gcc to link in the specified library.
Linker merges all the sections of the same type into a new single section. For example, linker merges all the . data sections of all the input relocatable object files into a single . data section for the final executable.
Use gcc -v
to see what commands it runs. As in,
gcc -v -o hello hello.c
This will print a lot of output, including the linker command. The actual output depends on the platform, but the linking command should be near the end. Alternatively, use
gcc -### -o hello hello.c
This is like -v
, but does not actually run any commands and quotes the options.
Another option is
gcc -dumpspecs
Look for the entry for link
.
The above command line flags are listed in gcc --help
and explained on the man page. Here's GCC documentation for the spec files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With