-o

Category

Output control

Pragma equivalent

None.

Purpose

Specifies a name for the output object, assembler, or executable file.

Syntax

Read syntax diagramSkip visual syntax diagram
>>- -o--path---------------------------------------------------><

Defaults

See Types of output files for the default file names and suffixes produced by different phases of compilation.

Parameters

path
When you are using the option to compile from source files, path can be the name of a file or directory. The path can be a relative or absolute path name. When you are using the option to link from object files, path must be a file name.

If the path is the name of an existing directory, files created by the compiler are placed into that directory. If path is not an existing directory, the path is the name of the file produced by the compiler. See below for examples.

You can not specify a file name with a C source file suffix ( .c, .cpp, or .i), such as myprog.c or myprog.i; this results in an error and neither the compiler nor the linker is invoked.

Usage

If you use the -c option with -o together and the path is not an existing directory, you can only compile one source file at a time. In this case, if more than one source file name is listed in the compiler invocation, the compiler issues a warning message and ignores -o.

The -E, -P, and -qsyntaxonly options override the -o option.

Predefined macros

None.

Examples

To compile myprogram.c so that the resulting executable is called myaccount, assuming that no directory with name myaccount exists, enter:
xlc myprogram.c -o myaccount
To compile test.c to an object file only and name the object file new.o, enter:
xlc test.c -c -o new.o

Related information