Linking
The linker links specified object files to create one executable file. Invoking the compiler with one of the invocation commands automatically calls the linker unless you specify one of the following compiler options:
- -c
- -E
- -M
- -P
- -S
- -fsyntax-only (-qsyntaxonly)
- -### (-#)
- --help (-qhelp)
- --version (-qversion)
- Input files
- Object files, unstripped executable files, and library files serve as input to the linker. Object files must have a .o suffix, for example, filename.o. Static library file names have a .a suffix, for example, filename.a. Dynamic library file names typically have a .so suffix, for example, filename.so.
- Output files
- The linker generates an executable file and places it in
your current directory. The default name for an executable file is a.out.
To name the executable file explicitly, use the -o file_name option
with the compiler invocation command, where file_name is the
name you want to give to the executable file. For example, to compile myfile.c and
generate an executable file called myfile, enter:
If you use the -shared (-qmkshrobj) option to create a shared library, the default name of the shared object created is a.out. You can use the -o option to rename the file and give it a .so suffix.xlc myfile.c -o myfile
You can invoke the linker explicitly with the ld command. However, the compiler invocation commands set several linker options, and link some standard files into the executable output by default. In most cases, it is better to use one of the compiler invocation commands to link your object files. For a complete list of options available for linking, see Linking.
Note: If you want to use a nondefault linker, you can use
either of the following approaches:
- Use -t and -B or
use -qpath to
specify the nondefault linker, for example,
or-tl -Blinker_path
-qpath=l:linker_path
- Customize the configuration file of the compiler to use the nondefault linker. For more information about how to customize the configuration file, see Using custom compiler configuration files and Creating custom configuration files.