Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Options for selecting compilation phases

&pagelevel(4)&pagelevel

All of the options listed below always suppress the linkage run and cause any link editor options and operands that may have been specified to be ignored.

-c

Terminates the compiler run after an LLM has been created and placed into an object file file.o for each compiled source file. The object is written by default into the current directory. The -o option (see "General options") can be used to define a different file name and/or directory.

-E

The compiler run is terminated after the preprocessor phase and the result is written to the standard output stdout. Any blank lines present in the file are combined in the process, and the corresponding #line directives are generated. By default, C and C++ comments are removed from the preprocessor output (see the -C option in section "Preprocessor options"). If the -o option is specified (see "General options"), the result of the preprocessor run is written to a file instead of the standard output stdout.

-M

The compiler run is terminated after the preprocessor phase; however, instead of the normal preprocessor output (cf. -E, -P), a list of dependency lines that is suitable for further processing with the POSIX make program is generated and written to the standard output stdout. If the -o option is specified (see "General options"), the file dependency list is written to a file instead of the standard output stdout.

Note

Templates in C++ 2017, C++ 2020 and C++ V3 sources are not included implicitly.

-P

The compiler run is terminated after the preprocessor phase, and the result is written to a file named file.i (cc/c11/c89 command) or file.I (CC command) and placed in the current directory instead of the standard output stdout as in the -E option. The output does not contain any additional #line directives. By default, C or C++ comments are removed from the preprocessor output (see the -C option on "Preprocessor options"). file.i can be subsequently compiled further with the cc/c11/c89/CC commands, whereas file.I can only be compiled with the CC command. If desired, the -o option (see "General options") may be used to specify another file name and/or directory.

-y

This option can only be specified with the CC command in the modes C++ 2017, C++ 2020 and C++ V3.
The compiler run is terminated after the prelinker phase (automatic template instantiation), and an object file named sourcefile.o containing the instantiated templates is generated for each compiled source file. This is meaningful for objects that are to be subsequently incorporated in a library (.a library) or in a prelinked object file (-r); no automatic instantiation is performed for templates within libraries or prelinked object files. Note that the -y option can only be meaningfully used in the default automatic instantiation mode (-T auto).

Example

Contents of the source files (extracts):

// a.h:

class A {int i;};

// f.h:

template <class T> void f(T)
{
   /* any code */
}

// b.c:

#include "a.h"
#include "f.h"
void foo() {
   A a;
   f(a);
}

// main.c:

extern void foo();

int main(void)
{
   foo();
}

Commands:

CC -c b.c

The first compilation produces an object file b.o and a template information file b.o.ii, where each contains an entry that the function f(A) is not instantiated.

CC -y b.o

The b.o and b.o.ii files generated in the first compilation run are updated, and the function f(A) is instantiated.

ar -r x.a b.o

The module in b.o is added to the library x.a.

CC main.c x.a

An executable file named a.out is generated.

The following command sequence, by contrast, would not produce the desired result:


rm *.o *.ii *.a a.out   /* Cleanup the current directory */
CC -c b.c
ar -r x.a b.o
CC main.c x.a

This command sequence results in an error message. This is because the function f(A) cannot be found, since no automatic instantiation is performed for the templates in the library x.a.