Linking your compiled applications with IBM Open XL C/C++
The linker links specified object files to create one executable file.
- -c
- -E
- -S
- -fsyntax-only
- -###
- --help
- --version
file1.C
and
file3.C
to produce object files file1.o
and
file3.o
; after that, all object files, including file2.o
, are
submitted to the linker to produce one
executable.ibm-clang++_r file1.C file2.o file3.C
Valid input and output files
- 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
. Library file names have a.a
or.so
suffix, for example,filename.a
, orfilename.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 compilemyfile.c
and generate an executable file calledmyfile
, enter:
If you use the -shared option to create a shared library, the default name of the shared object created is shr.o. You can use the -o option to rename the file and give it aibm-clang myfile.c -o myfile
.so
suffix.
How to compile without linking
By default, an invocation command calls both the compiler and the linker. It accepts all linker options and passes linker options to the linker. To compile source files without linking, use the -c compiler option. The -c option stops the compiler after compilation is completed and produces output, an object file file_name.o for each file_name.nnn input source file, unless you use the -o option to specify a different object file name. You can link the object files later using the same invocation command, specifying the object files without the -c option.
For example, you can use the -c option to produce the object files
for file1.C
, file2.C
, and file3.C
. The object files can be linked later
with ibm-clang++_r
.
ibm-clang++_r -c file1.C # Produce one object file (file1.o)
ibm-clang++_r -c file2.C file3.C # Or multiple object files (file1.o, file3.o)
ibm-clang++_r file1.o file2.o file3.o # Link object files with default libraries
How to invoke the linker explicitly
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.