[Next] [Previous] [Up] [Top] [Contents] [Index]

Chapter 16: Software Development

16.4 C and FORTRAN Compiler Options

The default compiler options will produce a usable program on any of the supported platforms, however they may not be optimal for many situations. Several additional options are discussed in this section.

A caveat: One very annoying "feature" of the f77 and cc commands is that some of the options must be specified with whitespace (at least one blank character) between the option identifier and the option value, others without whitespace and still others with or without, according to the user's choice. For instance, on IRIX systems, there must be whitespace between -o and the name of the executable file but there must not be any whitespace between -l and the library file name.

If compilers are upgraded it is possible that some of these options could change. For full details on all the options, see the man pages and the vendor compiler documentation.

16.4.1 Commonly-Used Options

-c

suppress linking, produce object file *.o. The linker is called as part of the compilation process by default.

-L directory

add directory to the default linker search list; not needed for user libraries. The -L option adds directories to the linker's default search path. -L directories are searched ahead of system library areas. A user library could accidentally match the name of an obscure system library, with startling results.

-lfile

search library libfile.a, from the default areas (the lib gets prefixed and the .a appended automatically)

With user-written libraries, specify the libraries on the command line with their true file names and a full path, without using the -L and -l options.

-o file

(lower case o) produce executable program file rather than a.out

-On

(upper case O) optimize at level n where n is 0, 1, 2, 3, or 4. The meanings of the different optimization levels vary from system to system. See the man pages for details.

-w

suppress informational and non-fatal compiler warnings

-P

(upper case P) run cpp (C preprocessor) only to produce *.i source listing

-p

(lower case p) enable profiling; see the man pages for details

Other commonly-used C compiler options are:

-I directory_name

extend include path

-D

set value of preprocessor macro

Other commonly-used FORTRAN compiler options are:

-u

IMPLICIT NONE

-C

(upper case C) check runtime subscript range

16.4.2 Recommended Options for General Use

As mentioned earlier, the default options may not be optimal for a number of very common situations, namely for debugging, moving binary code between non-identical machines, or tuning for best performance. Even for general usage, some non-default options have proven helpful in avoiding internal compiler limits and providing better compatibility for migrated code.

This list shows options by platform which apply to all situations, and which we recommend for general use. They can be used in addition to other options you might choose based on your specific needs. As stated above, if compilers are upgraded it is possible that some of these options could change, so you should always consult the man pages.

AIX

-qextname -qrndsngl

-qflttrap=invalid:overflow:zerodivide:enable

IRIX

-trapuv -lfpe

OSF1

(none)

SunOS

-xl -fnonstd

Discussion of General Options

-qextname

(AIX) append underscore (_) to external names (default at Fermilab). This is needed if you use any Fermilab or CERN libraries. Better to just make it a habit.

-qrndsngl

(AIX) standard IEEE math on intermediate REAL*4 results. This produces bitwise identical results to IRIX/OSF1/SunOS for most programs, making port testing easier.

-qflttrap

(AIX) detect and report floating point errors. Without this, errors occur silently, and incorrect results may be produced. Unlike other platforms, these would not be NaN[78], but legitimate floating numbers. Do not use the :imprecise option here, as it appears to disable error detection entirely (AIX 3, XLF 2).

-trapuv

(IRIX) set uninitialized variables to NaN, to help catch nonportable code and latent bugs at runtime.

-lfpe

(IRIX) use the Floating Point Exception library, to report or core dump on errors. Without -lfpe, errors produce NaN values silently. Must be combined with the TRAP_FPE environment variable, or calls to handle_fpes, to be effective. TRAP_FPE must be set to the value:

OVERFL=ABORT;DIVZERO=ABORT;INVALID=ABORT

See section 9.1 for setting environment variables.

-xl

(SunOS) Extended Language, for Fermilab-required extensions (see section 16.2.2)

-fnonstd

(SunOS) trap floating point errors.

16.4.3 Debugging Option

The -O's here are all upper case, for optimization.

-g

include full symbol table for debugger. This option interacts with the optimizer differently on each platform, so we provide some usage notes:

AIX

you should not use -O with -g

IRIX

-g forces optimization off; use -g3 to permit optimization

OSF1

-g changes default optimization to -O0 (dash, letter-O, zero)

An additional OSF1 option, -synchronous_exceptions, puts traps after each floating point operation. This is very slow, but will precisely locate floating point errors. Use this only for code which is known to produce floating point exceptions.

SunOS

you should use -O1 with -g

16.4.4 Portability Option for AIX

-qnomaf

Turns off Multiply/Add instructions in order to enhance portability.

16.4.5 ABI Options Under IRIX 6

Under IRIX 6, there are three Application Binary Interface (ABI) options available. The selected option specifies at compile time which subset of the processor chip's capabilities is to be used. In previous releases of IRIX, and in all releases of the other supported UNIX flavors (as of this writing), the user is not given a choice of ABI. Under IRIX 6, choosing an ABI is generally necessary if you're doing mixed-language programming or using any libraries other than those supplied by the vendor. The available ABIs and their associated command line options are:

O32 (-32)

conforms to the ABI used with all prior IRIX releases

N64 (-64)

puts the processor into full 64-bit mode

N32 (-n32)

leaves the processor in 32-bit mode but takes advantage of a number of newer features and generally produces more efficient code on the newer processors

[Missing image]This topic is discussed in the Web page IRIX 6 Application Binary Interfaces, available under Physics Applications on the CD home page (look under Cern Library at Fermilab).

16.4.6 Speed Optimization Options

Note that on most platforms a combination of options is required for best optimization. Recall that these options may be used in addition to general recommended and other options. The -O's here are all upper case.

AIX

-O2

IRIX

-O3 -mips2

OSF1

-O3 -feedback -tune host

SunOS

-O3 -cg92 -libmil

Discussion of Speed Optimization Options

Platform

Options

Comment

IRIX

-mips2

Use full R4000 instruction set. This is important on R4000 and later systems.

OSF1

-feedback

-tune host

Order routines for best cache performance, based on actual program execution statistics.

Use best optimization for given generation of chip. The code will run anywhere, but is tuned for local speed.

SunOs

-cg92

-libmil

SuperSPARC V8 instruction set Sparcstation 2 and later. See the man fpversion document.

Hardware-specific inline math

16.4.7 Load Map Option

The load map option is actually a linker option. On AIX, IRIX and OSF1 this requires passing to the link phase the option that controls production of a load map.

Platform

Option

Output

AIX

-Wl,-bmap:file

file

IRIX/OSF1

-Wl,-m

stdout (SysV style list of input/output)

IRIX/OSF1

-Wl,-M

stdout (BSD style primitive map)

SunOS

-m

stdout

Additionally, under AIX two related options are available:

-Wl,-bloadmap provides additional internal loader information

-Wl,-bxref provides additional cross reference information

16.4.8 Special FORTRAN Compiler Options

Source Code Listing Option

Each platform has an option that produces a source code listing. The file extensions for these listings are platform-dependent.

Platform

Option

Listing Extension

AIX

-qsource

lst

IRIX

-listing

L

OSF1

-V

l

SunOS

-Xlist

lst

Saving Local Variables

The FORTRAN 77 standard allows subprogram local variables to become undefined between calls, unless saved with a SAVE statement. Many UNIX f77 compilers require the SAVE statements for retained local variables. SAVE'd variables are usually called static, and unSAVE'd variables are called automatic. For programs not yet properly equipped with SAVE statements, f77 command line options are available as follows:

Platform

Static Option

Automatic Option

AIX

(default)

-qnosave

IRIX

-static

-automatic (default)

OSF1

-static (default)

-automatic

SunOS

(default)

-stackvar

C Preprocessor

The C preprocessor (cpp), a macro processor, is used in f77 for conditional compilation, macro expansion and source inclusion. If you plan to run cpp, remember to double any backslash characters (\\) in your code to prevent their misinterpretation as cpp escapes. The option shown in parentheses is the default option for the corresponding platform:

IRIX

(-cpp) -nocpp

OSF1

-cpp (-nocpp)

SunOS

any input file name *.F is automatically preprocessed by cpp

AIX

(see below)

The C preprocessor cannot be invoked through the f77 command on AIX systems. It can, however, be invoked under AIX as a separate command:

% /lib/cpp -P -C infile outfile

See the man pages for cpp syntax and usage information.

Extend Search Path for INCLUDE

Use the f77 command line option -I path to extend the search path for the INCLUDE statement on AIX/IRIX/OSF1 (not supported on SunOS), where path is the path to the directory where the include files are found.

Internal Compiler Limits

You may need to set one of these if you are compiling a very large single source file.

AIX

-NQ20000

Larger internal compiler tables. This value should be big enough for almost all programs.

IRIX/OSF1

-Olimit 1500

Allows somewhat larger routines to be optimized.


[78] NaN is the IEEE standard Not-a-Number bit pattern produced when a floating point operation generates invalid results.

UNIX at Fermilab - 10 Apr 1998

[Next] [Previous] [Up] [Top] [Contents] [Index]