This chapter discusses C++ compiling and linking for the MIPSpro compilers. It contains the following sections:
“The C++ Command Line”, discusses the syntax of the C++ command and the options used with that command.
“Compiling and Linking”, describes the SGI C++ compilation process.
“Object File Tools”, briefly summarizes the capabilities of the tools that provide symbol and other information on object files.
This section provides an overview of the CC (1) command. For complete details about each option, see the CC man page.
The CC command invokes the compiler. The following syntax box shows the complete CC command syntax (note that cc command syntax is not indicated here).
CC [-64|-n32] [-all] [-anach] [-ansiE] [-ansiW] [-apo] [-apokeep] [-apolist] [-ar] [-auto_include] [-bigp_off] [-bigp_on] [-brief_diagnostics] [-c] [-cfront] [-common] [-D name=def] [-DEBUG] [-diag_error numberlist] [-diag_remark numberlist] [-diag_suppress numberlist] [-diag_warning numberlist] [-dollar] [-E] [-fb file] [-fb_create path] [-fb_opt path] [-fbgen] [-fbuse file] [-FE:eliminate_duplicate_inline_copies] [-FE:template_in_elf_section] [-float] [-float_const][-fullwarn] [-G num] [-g[n]] [-gslim] [-help] [-I dir] [-ignore_suffix] [-INLINE] [-IPA] [-J #] [-KPIC] [-L directory] [-l library] [-LANG] [-LIST] [-LNO] [-M] [-MDupdate filename] [-mipsn] [-MP] [-mp] [-mplist] [-no_auto_include] [-noinline] [-non_shared] [-no_prelink] [-none] [-nostinc] [-o outfile] [-O[n]] [-Ofast [= ipxx]] [-OPT:] [-P] [-pch] [-pedantic] [-prelink] [-pta] [-ptall] [-ptnone] [-ptused] [-ptv] [-quiet_prelinker] [-r] [-rprocessor] [-S] [-shared] [-show] [-signed] [-TARG] [-TENV] [-trapuv] [-U name] [-use_command] [-use_readonly_const] [-use_readwrite_const] [-use_suffix] [-v] [-version] [-W c,arg1 [,arg2...]] [-w] [-w2] [-woff all] [-woff numberlist] [-x lang] [-Xcpluscomm] [-Y c,path] files |
In some cases, more than one option can have an effect on a single compiler feature. The following list shows some of the compiler features and the options that affect them:
Source preprocessing: -Dvar[ =def][,var[ =def]]..., -E, -nocpp, -P, -Uname.
Setting the compilation environment: -n32, -64, -mipsn, -rprocessor, -TARG:, -TENV:.
Optimization: -apo, -LNO:, -OPT:, -Olevel.
![]() | Note: In order to use the APO command line options, you must be licensed for the MIPSpro Auto-Parallelizing Option. |
Various environment variable settings can affect your compilation. For more information on the environment variables, see the pe_environ(5) man page.
Some CC(1) command options, for example, -LNO:..., -LIST:..., -MP:... , -OPT:..., -TARG:..., and -TENV:... accept several suboptions and allow you to specify a setting for each suboption. To specify multiple suboptions, either use colons to separate each suboption or specify multiple options on the command line. For example, the following command lines are equivalent:
% CC -LIST:notes=ON:options=OFF b.c % CC -LIST:notes=ON -LIST:options=OFF b.c |
Some arguments to suboptions of this type are specified with a setting that either enables or disables the feature. To enable a feature, specify the suboption either alone or with =1, =ON, or =TRUE. To disable a feature, specify the suboption with either =0, =OFF, or =FALSE . For example, the following command lines are equivalent:
% CC -LNO:auto_dist:blocking=OFF:oinvar=FALSE a.c % CC -LNO:auto_dist=1:blocking=0:oinvar=OFF a.c |
For brevity, this manual shows only the ON or OFF settings to suboptions, but the compiler also accepts 0, 1, TRUE, and FALSE as settings.
The following list summarizes the options to the CC command. For complete details, see the CC(1) man page.
The two compilation processes in Figure 2-1, show what transformations a C++ source file, foo.C, undergoes with the N32, 64, and O32 compilers. The MIPSpro compilation process is on the left, invoked by specifying either -n32 or -64 mode, as shown in the following examples:
CC -n32 -o foo foo.C |
CC -64 -o foo foo.C |
On the right is the O32 compilation process, invoked by using -o32, as shown in the following example:
CC -o32 -o foo foo.C |
The following steps further describe the compilation stages in Figure 2-1:
You invoke CC on the source file, which has the suffix .C. The other acceptable suffixes are .c++, .c, .cc, .cpp, .CPP, .cxx, or .CXX.
The source file passes through the C++ preprocessor, which is built into the C++ compiler.
The complete source is processed using a syntactic and semantic analysis of the source to produce an intermediate representation.
This stage may also produce a prelink (.ii) file, which contains information about template instantiations.
Optimized object code (foo.o) is then generated.
This command produces object code, foo.o, that is suitable for later linking.
The compiler processes the .ii files associated with the objects that will be linked together. Then sources are recompiled to force template instantiation.
The object files are sent to the linker, ld (see the ld(1) man page), which links the standard C++ library libC.so and the standard C library libc.so to the object file foo.o and to any other object files that are needed to produce the executable.
In -o32 mode, the executable object is sent to c++patch, which links it with global constructors and destructors. If global objects with constructors or destructors are present, the constructors need to be called at run time before function main() , and the destructors need to be called when the program exits. c++patch modifies the executable, a.out, to ensure that these constructors and destructors get called.
The following are some typical C++ compiler command lines:
To compile one program and suppress the loading phase of your compilation, use the following command line:
CC -c program |
To compile with full warnings about questionable constructs, use the following command line:
CC -fullwarn program1 program2 ... |
To compile with warning messages off, use the following command line:
CC -w program1 program2 ... |
C++ programs can be compiled and linked with programs written in other languages, such as C, Fortran, and Pascal. When your application has two or more source programs written in different languages, you should do the following:
Compile each program module separately with the appropriate compiler.
Link them together in a separate step.
You can create objects suitable for linking by specifying the -c option. For example:
CC -c main.c++ f77 -c module1.f cc -c module2.c |
The three compilers produce three object files: main.o, module1.o, and module2.o. Since the main module is written in C++, you should use the CC command to link. In fact, if any object file is generated by C++, it is best to use CC to link. Except for C, you must explicitly specify the link libraries for the other languages with the -l option. For example, to link the C++ main module with the Fortran submodule, use the following command line:
CC -o almostall main.o module1.o -lftn -lm |
For more information on C++ libraries, see “C++ Libraries” in Chapter 1.
The following object file tools are of special interest to the C++ programmer:
nm: this tool can print symbol table information for object and archive files.
c++filt: this tool, specifically for C++, translates the internally coded (mangled) names generated by the C++ translator into names more easily recognized by the programmer. You can pipe the output of stdump or nm into c++filt, which is installed in the /usr/lib/c++ directory. For example:
nm a.out | /usr/lib/c++/c++filt |
libmangle.a: the /usr/lib/c++/libmangle.a library provides a demangle(char *) function that you can invoke from your program to output a readable form of a mangled name. This is useful for writing your own tool for processing the output of nm, for example. You must declare the following in your program, and link with the library using the -lmangle option:
char * demangle(char *); |
size: the size tool prints information about the text, rdata, data, sdata, bss, and sbss sections of the specific object or archive file.
elfdump: the elfdump tool lists the contents of an ELF (Executable and Linking Format) object file, including the symbol table and header information. See the elfdump(1) man page for more information.
stdump: the stdump tool outputs a file of intermediate-code symbolic information to standard output for O32 executables only. See the stdump(1) man page for more information.
dwarfdump: the dwarfdump tool outputs a file of intermediate-code symbolic information to standard output for -n32 and -64 compilations. See the dwarfdump(1) man page for more information.
For more complete information on the object file tools, see the MIPSpro N32/64 Compiling and Performance Tuning Guide.