Invoke the C and C++ Compilers

The commands for invoking the C and C++ compilers.

The following commands invoke the compilers:
  • CC invokes the Cray C++ compiler.
  • cc invokes the Cray C compiler.
  • cpp, the C language preprocessor, is not part of CCE. The cpp command resolves to the GNU cpp command and does not predefine any Cray compiler-specific macros. If the predefinition of the Cray compiler-specific macros is required, then use the cc or CC command to do the source preprocessing using the -E or -P option.

A successful compilation creates an executable file, named a.out by default, that reflects the contents of the source code and any referenced library functions. Use the aprun command to run the executable on the compute nodes.

Simple C compiler invocation and application execution

% cc mysource.c; aprun -n 64 ./a.out

By default, the CC and cc commands automatically call the linker, which creates an executable file. If only one source file is specified, the object file (*.o) is deleted. If more than one source file is specified, the object files are retained.

Simple C compiler invocation using multiple source files

The following command creates and retains object files file1.o, file2.o, and file3.o, and creates the executable file a.out.

% cc file1.c file2.c file3.c

Simple C compiler invocation using single source file

The following command creates file.o and a.out; file.o is not retained.

% cc file1.c

CC Command

CC [ -c] [-C] [ -D macro[=def]] [-E] [-g] [-G level ] [-h arg] [ -I incldir] [ -K trap=opt,opt ...] [ -l libfile] [ -L ldir] [ -M] [-nostdinc] [ -o outfile] [-O level] [-P] [-S] [-U macro] [-V] [-Wphase,"opt ..."] [-X npes] [-Yphase, dirname] [-#] [-##] [-###] sourcefile . . .
The CC command invokes the Cray C++ compiler and accepts C++ source files with the following suffixes:
  • .c
  • .C
  • .i
  • .c++
  • .C++
  • .cc
  • .cxx
  • .Cxx
  • .CXX
  • .CC

The .i files are created when the preprocessing compiler command option (-P) is used. The CC command also accepts object files with the .o suffix, library files with the .a suffix, and assembler source files with the .s suffix.

cc Command

cc [ -c] [-C] [ -D macro[=def]] [-E] [-g] [-G level ] [-harg ] [ -I incldir] [ -K trap=opt[,opt] ...] [ -l libfile] [ -L ldir] [ -M] [-nostdinc] [ -o outfile] [-O level] [-P] [-S] [-U macro] [-V] [-Wphase,"opt ..."] [-X npes] [-Yphase, dirname] [-#] [-##] [-###] sourcefile . . .

The cc command invokes the Cray C compiler. The cc command accepts C source files that have the .c and .i suffixes; object files with the .o suffix; library files with the .a suffix; and assembler source files with the .s suffix.

File Types Used or Created by the Compiler

The compiler uses and creates several types of files during processing:
a.out
Default name of the executable output file. Use the compiler driver command line option -o to specify an executable name other than a.out.
.c, .C, .c++, .C++, .cc, .cxx, .Cxx, .CXX, .CC
C++ source files
.c
C source files
.i
Files containing output from the source preprocessor
.o
Relocatable object code. During compilation, these relocatable object files are saved in the current directory automatically. If using CrayPat to conduct performance analysis experiments, the object files created during compilation must be kept in order to preserve source-to-executable function mapping. To do so, use the -h keepfiles option.
.a
Library files containing external references
.s
Assembly language files. Files with .s extensions are assembled and written to the corresponding .o file.

Command Line Examples

The following examples illustrate a variety of command lines for the C and C++ compiler commands:

CC -h conform myprog.C

This example compiles myprog.C. The -h conform option specifies strict conformance to the ISO C++ standard.
% CC -h conform myprog.C

cc -c -h ipa1 myprog.c subprog.c

This example compiles input files myprog.c and subprog.c. The -c option tells the compiler to create object files myprog.o and subprog.o but not call the linker. Option -h ipa1 tells the compiler to inline function calls marked with the inline_always pragma.
% cc -c -h ipa1 myprog.c subprog.c

cc -I. disc.c vend.c

This example specifies that the compiler search the current working directory, represented by a period (.), for #include files before searching the default #include file locations.
% cc -I. disc.c vend.c

cc -P -D DEBUG newprog.c

This example specifies that source file newprog.c be preprocessed only. Compilation and linking are suppressed. In addition, the macro DEBUG is defined.
% cc -P -D DEBUG newprog.c

cc -c -h report=s mydata1.c

This example compiles mydata1.c, creates object file mydata1.o, and produces a scalar optimization report to stdout.
% cc -c -h report=s mydata1.c

CC -h ipa5,report=if myfile.C

This example compiles myfile.C and tells the compiler to attempt to aggressively inline calls to functions defined within myfile.C. An inlining report is directed to myfile.V.
% CC -h ipa5,report=if myfile.C

Compile Time Environment Variables

The following environment variables are used during compilation.
CRAYOLDCPPLIB
When set to a nonzero value, enables C++ code to use the following nonstandard Cray C++ headers files:
  • common.h
  • complex.h
  • fstream.h
  • generic.h
  • iomanip.h
  • iostream.h
  • stdiostream.h
  • stream.h
  • strstream.h
  • vector.h
To use the standard header files, the code may require modification to compile successfully. For more information, see Cray C and C++ Dialect Use.
Setting the CRAYOLDCPPLIB environment variable disables exception handling, unless compiling with the -h exceptions option.
CRI_CC_OPTIONS, CRI_cc_OPTIONS
Specifies command line options that are applied to all compilations. Options specified by this environment variable are added following the options specified directly on the command line. This is especially useful for adding options to compilations done with build tools.
Identifies the requirements for native language, local customs, and coded character set with regard to compiler messages.
Controls the format in which compiler messages are received.
Specifies the message system catalogs that should be used.
Specifies the number of processes used for simultaneous compilations The default is 1. When more than one source file is specified on the command line, compilations may be multiprocessed by setting the environment variable NPROC to a value greater than 1. NPROC can be set to any value; however, large values can overload the system.

Run Time Environment Variables

CRAY_MALLOPT_OFF
If set, then the system default mallopt parameters are used, instead of the compiler default parameters. For most programs, run time performance is improved by using the compiler defaults, but more memory may be used.
MALLOC_MMAP_MAX_
Specifies the maximum number of memory chunks to allocate with mmap. The compiler default value is 0. For most programs, run time performance is improved by using the compiler default, but more memory may be used.
MALLOC_TRIM_THRESHOLD_
Specifies the minimum size of the unused memory region at the top of the heap before the region is returned to the operating system. The compiler default value is 536870912 bytes. For most programs, run time performance is improved by using the compiler default, but more memory may be used.
PGAS_ERROR_FILE
Specifies the location to which libpgas (the library which provides an interface to the internal system network) error messages are written. The default is stderr. If stdout is specified, errors will be written to standard output.
CRAYLIBS_ARCH_OVERRIDE

Override the default Cray math library run time selection and specify the library to use by CPU architecture. The valid options are: haswell, ivybridge, sandybridge, interlagos, abudhabi, interlagos-cu, abudhabi-cu, mc8, mc12, istanbul, shanghai, barcelona, opteron, x86-64, or mic-knl.

This run time environment variable can be used to specify that a lowest-common-denominator math library be used instead of the default selection, thus ensuring that identical computations produce identical results regardless of the type of compute node CPU actually used. The trade-off is that specifying an older library may affect performance on a newer CPU. For example, if ivybridge is specified, the code will run and produce identical results on a haswell compute node, but performance may be reduced.

Default: If not set, the library specific to the type of CPU selected at run time is used.