HPlogo HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 9 Compiling and Running HP C Programs

Compiling HP C Programs

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

When you compile a program, it passes through one or more of the following steps depending upon which command line options you use:

  • Preprocessor: This phase examines all lines beginning with a # and performs the corresponding actions and macro replacements.

  • Compilation Process: This phase takes the output of the preprocessor and generates object code.

  • Optimization: This optional phase optimizes the generated object code.

  • Linking: In this phase, the linker is invoked to produce an executable program. External references in shared and archived libraries are resolved as required. The startup routines are copied in, and the C library in /usr/lib/hpux##/lib.so (## is 32 or 64) is referenced. (By default, shared libraries take precedence over archived libraries if both versions are available. However, if you use the LPATH environment variable, you should make sure that all shared libraries come before any archive library directories. See the HP-UX Linker and Libraries Online User Guide for information on LPATH or on creating and linking with shared libraries.) Object modules are combined into an executable program file.

The cc(1) Command

Use the cc(1) command to compile HP C programs. It has the following format:

cc [options] files

where:

options

is one or more compiler options and their arguments, if any. Options can be grouped together under one minus sign.

files

is one or more file names, separated by blanks. Each file is either a source or an object file.

Specifying Files to the cc Command

Files with names ending in .c are assumed to be HP C source files. Each HP C source file is compiled, producing an object file with the same name as the source file except that the .c extension is changed to a .o extension. However, if you compile and link a single source file into an HP C program in one step, the .o file is automatically deleted.

Files with names ending in .i are assumed to be preprocessor output files (see the -P compiler option in Table 9-2 “HP C Compiler Option Details ” in this chapter). Files ending in .i are processed the same as .c files, except that the preprocessor is not run on the .i file before the file is compiled.

Files with names ending in .s are assumed to be assembly source files; the compiler invokes the assembler to produce .o files from these.

Files with .o extensions are assumed to be relocatable object files that are included in the linking. All other files are passed directly to the linker by the compiler.

Specifying Options to the cc Command

Each compiler option has the following format:

     -optionname [optionarg]

where:

optionname

is the name of a standard compiler option.

optionarg

is the argument to optionname.

The optional argument -- delimits the end of options. Any following arguments are treated as operands (typically input filenames) even if they begin with the minus (-) character.

An Example of Using a Compiler Option

By default, the cc command names the executable file a.out. For example, given the following command line:

cc demo.c

the executable file is named a.out.

You can use the -o option to override the default name of the executable file produced by cc. For example, suppose my_source.c contains C source code and you want to create an executable file name my_executable. Then you would use the following command line:

cc -o my_executable my_source.c

Concatenating Options

You can concatenate some options to the cc command under a single prefix. The longest substring that matches an option is used. Only the last option can take an argument. You can concatenate option arguments with their options if the resulting string does not match a longer option.

For example, suppose you want to compile my_file.c using the -v, -g, and -DPROG=sub compiler options. There are several ways to do this:

cc my_file.c -v -g -DPROG=sub
cc my_file.c -vg -D PROG=sub

cc my_file.c -vgDPROG=sub
cc -vgDPROG=sub my_file.c

HP C Compiler Options

Table 9-1 “HP C Compiler Options at a Glance ” summarizes the command line options supported by HP 9000 workstations and servers. See Table 9-2 “HP C Compiler Option Details ” for detailed information about each option.

Table 9-1 HP C Compiler Options at a Glance

Option

Description

-Aa

Enables strict ANSI C compliance.

-AC89

Enable ANSI C89 compliance.
-AC99Enable ANSI C99 compliance.

-Ae

Enables ANSI C89 compliance, HP value-added features (as described for +e option), and _HPUX_SOURCE name space macro. It is equivalent to -AC89 +e.

-BexternPerforms the same operation as +Oextern=sym1,sym2,sym3... except that symbols are loaded from an existing file, instead of specified on the command line.

-c

Compiles only, does not link.

-C

Prevents the preprocessor from stripping comments.

-Dname

Defines the preprocessor variable name with a value of "1".

-Dname=def

Defines the preprocessor variable name with a value of def.

-dynamicEnables linking of PIC objects.

-E

Performs preprocessing only with output to stdout.

-g

Inserts information for the symbolic debugger in the object file.

-G

Inserts information required by the gprof profiler in the object file.

-Idir

Inserts dir in the include file search path.

-lx

Links with the /lib/libx.a and /usr/lib/libx.a libraries.

-Ldir

Links the libraries in dir before the libraries in the default search path.

-minsharedIndicates that the result of the current compilation is going into an executable file that will make minimal use of shared libraries. This option is equivalent to -exec -Bprotected.

-n

Generates shareable code.

-N

Generates unshareable code.

-o outfile

Places object modules in outfile file.

-O

Optimizes at level 2.

-p

Inserts information required by the prof profiler in the object file.

-P

Performs preprocessing only with output to the corresponding .i file.

-q

Marks the executable as demand loadable.

-Q

Marks the executable as not being demand loadable.

-s

Strips the symbol table from the executable file.

-S

Generates an assembly language source file.

-t x,name

Substitutes or inserts subprocess x with name.

-Uname

Undefines name in the preprocessor.

-v

Enables verbose mode.

-V

Causes subprocesses to print version information to stderr.

-w

Suppresses warning messages.

-Wx, arg1 [,arg2,..,argn]

Passes the arguments arg1 through argn to the subprocess x.

-Y

Enables Native Language Support (NLS).

-z

Disallows run-time dereferencing of null pointers.

-Z

Allows dereferencing of null pointers at run-time.

+DCapptypeGenerate code for portable or embedded applications.
+DD32Generates 32-bit code for PA1.1 architecture.
+DD64Generates 64-bit code for PA2.0 architecture.

+DSmodel

Performs instruction scheduling for a specific implementation of PA-RISC.

+DOosnameSets the target operating system for the compiler.

+e

Enables the following HP value added features while compiling in ANSI C mode: sized enum, long long, long pointers, compiler supplied defaults for missing arguments to intrinsic calls, and $ in identifier HP C extensions.

+FPflags

Controls floating-point traps.

+help

Launches a web browser displaying an html version of the HP C/HP-UX Online Help.

+M

Provides ANSI migration warnings that explain the differences between code compiled with -Ac and -Aa.

+M1Provides platform migration warnings for features that may not be supported in future releases.
+M2Provides migration warnings for transitioning code from the ILP32 to the LP64 data model.

+o

Prints hexadecimal code offsets in the source code listing.

+OlitThis option places the data items that do not require load-time or run-time initialization in a read-only data section. +Olit can take the values all, const and none. The default value is +Olit=const.

+[no]objdebug

When used with -g, +objdebug leaves debug information in the object files instead of copying it to the executable file. The object files must be accessible to the HP WDB debugger when debugging.

+Oprofile=collect

Prepares the object code for profile-based optimization data collection.

+Oprofile=use

Performs profile-based optimization.

+Oprofile=use:name

Specifies the profile database to use with profile-based optimization.

+sbMake bit-fields signed by default in both 32- and 64-bit modes.

+ubytes

Controls pointer alignment where bytes is 1, 2, or 4.

+ucMakes unqualified char data types unsigned.

+wn

Specifies the level of the warning messages where n is 1 - 3.

+W n1[,n2,...nN]

Suppresses the specified warnings.

+We n1[,n2,...nN]

Changes the specified warnings to errors.

+Ww n1[,n2,...nN]

Enables the specified warnings, assuming all other warnings are suppressed with -w or +w3.

+z

Generates shared library object code (same as +Z in 64-bit mode).

+Z

Generates shared library object code with a large data linkage table (long-form PIC).

 

Table 9-2 “HP C Compiler Option Details ” describes in detail the options that HP C workstations and servers support.

Table 9-2 HP C Compiler Option Details

Option

What It Does

-Aa

Requests a compilation in ANSI C mode. The -Aa option requests a strict implementation of ANSI C. ANSI C specifies which names are available in the standard libraries and headers, which are reserved for the implementation, and which must be left available for you. HP C in ANSI mode conforms to these restrictions and only names permitted by ANSI C are defined or declared in the standard libraries and headers. Macro definitions can be used to access names that are normally defined in other standards (POSIX and XOPEN, for example), and in HP C Version 3.1 compatibility mode. To gain access to all variables and functions defined by POSIX, include the following line at the start of your source file before including any system headers:

#define _POSIX_SOURCE

or define this macro by using the -D name option:

cc -D _POSIX_SOURCE myfile.c

To gain access to all the names defined by XOPEN, include the following line at the start of your source file before including any system headers:

#define _XOPEN_SOURCE

or define the macro on the command line:

cc -D _XOPEN_SOURCE myfile.c

To gain access to all the names normally available in compatibility mode, include the following line at the start of your source file before including any system headers:

#define _HPUX_SOURCE

or define the macro on the command line:

cc -D _HPUX_SOURCE myfile.c

_HPUX_SOURCE defines a superset of names defined by _XOPEN_SOURCE. _XOPEN_SOURCE defines a superset of names defined by _POSIX_SOURCE.

-AeRequests a compilation in ANSI C mode with HP C extensions. This option is the same as specifying -Aa, -D_HPUX_SOURCE, and +e. This is the default for the HP-UX 10.30 and later operating system releases.
-BexternPerforms the same operation as +Oextern=sym1,sym2,sym3... except that symbols are loaded from an existing file, instead of specified on the command line. -Bextern does not require that you manually specify symbols locally, on the command line. In fact, if you specify a locally-defined symbol with -Bextern, you may experience problems. When used, -Bextern tells the compiler that the symbols reside in a separate load module. -Bextern:filename fetches the list of symbols from a text file instead of locally. Symbols referenced in the file must be separated by white space within the file.
-BhiddenHides all the symbols including references except for those prefixed with __declspec(dllexport), __declspec(dllimport) or specified with +Oextern or HP_DEFINED_EXTERNAL pragma. This will hide both definitions and references.
-Bhidden_defHides all the symbols defined in the module except for those prefixed __declspec(dllexport). This will hide only definitions.
-cCompiles one or more source files but does not enter the linking phase. The compiler produces the object file (a file ending with .o by default) for each source file (a file ending with .c, .s, or .i). Object files must be linked before they can be executed.

-C

Prevents the preprocessor from stripping comments. See the description of cpp(1) in the HP-UX Reference Manual for details.

-Dname
-Dname=def

Defines name to the preprocessor cpp as if defined by the preprocessing directive #define. If =def is not given, name is "1".
Macros should be assigned integer values when they will be used in constant expressions that are to be evaluated by the conditional compilation directives #if and #else. See “Conditional Compilation (#if, #ifdef, ..#endif)” for more information.

-dynamicThis option produces dynamically bound executables. These support shared libraries and use the features of the dynamic loader. The shl_load and dlopen APIs are fully supported. The linker links in shared libraries first and then archive libraries. Only PIC is supported.

-E

Runs the preprocessor only on the named HP C or assembly programs and sends the result to standard output (stdout).

-fast

The -fast compiler option expands into an existing set of compiler options which, used together, result in optimum speed and application run-times. This option is also provided for compatibility in porting other vendors’ applications to HP-UX.

NOTE: Do not use this option for programs that depend on IEEE standard floating-point denormalized numbers. Otherwise, different numerical results may occur.

-fast expands to the following HP C/ANSI C options:

+O2, +Olibcalls, +Ofltacc=relaxed, +Onolimit, +DSnative, +FPD

You can override any of the options in -fast by specifying a subsequent option after it.

-g

Inserts information for the symbolic debugger in the object file. In conjunction with the HP Distributed Debugging Environment (DDE), the C compiler now provides support for debugging optimized code. This support includes:

  • Tracebacks with line-number annotation

  • Setting breakpoints and single-stepping at the source statement level

  • Mapping between source statements and machine instructions

  • Viewing and modifying global variables at procedure call boundaries

  • Viewing and modifying parameters on procedure entry

To enable debugging of optimized code, specify the -g compile-line option together with the -0, +01, or +02 option. Currently, debugging is supported at optimization levels 2 and below. If you try to use -g with the +03 or +04 option, the compiler will issue a warning stating that the options are incompatible, and will ignore the -g option.

-G

Prepares the object file for profiling with gprof. See the gprof(1) description in the HP-UX Reference manual for details.

-Idir

Adds dir to the list of directories that are searched for include files by the preprocessor. For include files that are enclosed in double quotes and do not begin with a /, the preprocessor first searches the current directory, then the directory named in the -I option, and finally, the standard include directory /usr/include. For include files that are enclosed in < and > symbols, the search path begins with the directory named in the -I option and is completed in the standard include directory, /usr/include. The current directory is not searched.

-lx

Causes the linker to search the libraries /usr/lib/libx.a or /usr/lib/libx.sl (searched first) and /opt/langtools/lib/libx.a or /opt/langtools/lib/libx.sl (searched second). The -a linker option determines whether the archive (.a) or shared (.sl) version of a library is searched. The linker searches the shared version of a library by default.

Libraries are searched when their names are encountered. Therefore placement of a -l is significant. If a file contains an unresolved external reference, the library containing the definition must be placed after the file on the command line. See the description of ld(1) in the HP-UX Reference Manual for details.

-Ldir

Causes the linker to search for libraries in the directory dir before using the default search path. The default search path is the directory /usr/lib followed by /opt/langtools/lib. -Ldir must precede -lx on the command line; otherwise -Ldir is ignored. This option is passed directly to the linker.
For example:

cc -L/project/libs prog.c -lfoo -lbar

Compiles and links prog.c and directs the linker to search the directories /project/libs, /usr/lib, then /opt/langtools/lib for libfoo.a, libfoo.sl, libbar.a, and libbar.sl libraries.

-n

Causes the program file produced by the linker to be marked as shareable. For details and system defaults see the description of ld(1) in the HP-UX Reference manual.

-N

Causes the program file produced by the linker to be marked as unshareable. For details and system defaults see the ld(1) description in the HP-UX Reference Manual.

-o outfile

Causes the output of the compilation sequence to be placed in outfile. The default name is a.out. When compiling a single source file with the -c option, you can also use the -o option to specify the name and location of the object file.

-O

Invokes the optimizer to perform level 2 optimization. Other optimization levels can be set. Refer to the HP C/HP-UX Programmer's Guide for details on optimization.

-p

Causes the compiler to produce extra profiling code that counts the number of times each routine is called. Also, if link editing takes place, this option replaces the standard startup routine with a routine that calls monitor(3C) at the start and writes out a mon.out file upon normal termination of the object program's execution. An execution profile can then be generated using prof(1).

-P

Preprocesses only. Runs the preprocessor with the -P option only on the named HP C source files and leaves the result in the corresponding files with .i as the suffix.

-q

Causes the output file from the linker to be marked as demand loadable. For details and system defaults, see the ld(1) description in the HP-UX Reference manual.

-Q

Causes the program file created by the linker to be marked as not demand loadable. For details and system defaults, see the ld(1) description in the HP-UX Reference manual.

-s

Strips the executable. Causes the program file created by the linker to be stripped of symbol table information. Specifying this option prevents using a symbolic debugger on the resulting program. See the ld(1) description in the HP-UX Reference manual for more details.

-S

Compiles the named HP C program and leaves the assembly language output in a corresponding file with .s as the suffix.

-t x,name

Substitutes or inserts subprocess x with name, where x is one or more of a set of identifiers indicating the subprocesses. This option works in two modes: 1) if x is a single identifier, name represents the full pathname of the new subprocess; 2) if x is a set of identifiers, name represents a prefix to which the standard suffixes are concatenated to construct the full pathnames of the new subprocesses. x can be one or more of the following values:

  • p—Preprocessor (standard suffix is cpp).

  • c—Compiler (standard suffix is ccom).

  • 0—Same as c.

  • a—Assembler (standard suffix is as).

  • l—Linker (standard suffix is ldr).

-Uname

Undefines or removes any initial definition of name in the preprocessor. See the cpp(1) description in the HP-UX Reference manual for details.

-v

Enables the verbose mode sending a step-by-step description of the compilation process to standard error (stderr.)

-V

Prints version information on each invoked subprocess to standard error (stderr.)

-w

Suppresses warning messages.

-Wx, arg1[,arg2,..,argn]

Passes the arguments arg1 through argn to the subprocess x of the compilation. x can be one of the values described under the -t option with the addition of d, to pass an option to the cc driver. These options are HP value added extensions to HP C.

-Y

Enables Native Language Support (NLS) of 8-bit and 16-bit characters in comments, string literals, and character constants. See hpnls(5), long(5), and environ(5) in the HP-UX Reference manual for a description of the NLS model.
The language value is used to initialize the correct tables for interpreting comments, string literals, and character constants. It is also used to build the pathname to the proper message catalog. Refer to “Location of Files ” for a description of this path.

-z

Disallows run-time dereferencing of null pointers. Fatal errors result if null pointers are dereferenced.

-Z

Allows dereferencing of null pointers at run-time. (This behavior is the default.) The value of a dereferenced null pointer is zero.

+DD32Generates 32-bit object code for the PA-RISC 1.1 architecture, which runs on PA1.1 and PA2.0 architectures. This option is the same as the options +DA1.1 and +DAportable.
+DD64Generates 64-bit object code for PA2.0 architecture. Causes the macro __LP64__ to be #defined. This is the same as +DA2.0W, but is the recommended option to use when compiling in 64-bit mode on the PA RISC 2.0 architecture because it is forward compatible with future 64-bit architectures.

+Oprofile=use:name

Specifies the path name of the profile database to use with profile-based optimization. This option can be used with the +Oprofile=use command line option. The profile database by default is named flow.data. This file stores profile information for one or more executables. Use this option when the flow.data file has been renamed or is in a different directory than where you are linking.

You can also use the FLOW_DATA environment variable to specify a different path and file name for the profile database file. The +Oprofile=usename command line option takes precedence over the FLOW_DATA environment variable.

Note, this option cannot be used to redirect the instrumentation output (with the +Oprofile=collect option). It is only compatible with the +Oprofile=use option.

+DOosname

Sets the target operating system for the compiler. The osname can be:

  • 11.22

  • 11.23

+DO can be used at any optimization level. By default, when you compile your application, it is binary compatible across the 11.x release. You only need to specify +DO when you want the latest performance features supported in the OS.

Caution: Use of +DO with a non-default osname makes the resulting code binary incompatible with an earlier version of HP-UX.

+DSmodel

Performs instruction scheduling tuned for a particular implementation of the Itanium®-based architecture.

Object code with scheduling tuned for a particular model will execute on other HP 9000 systems, although possibly less efficiently.

model can be either of four values.

  • blended

    Tune to run reasonably well on multiple implementations. As old implementation become less important and new implementations are added, the behavior with this value will change accordingly.

  • itanium

    Tune for the Itanium processor.

  • itanium2

    Tune for the Itanium2 processor

  • native

    Tune for the processor on which the compiler is running

The default is blended.

+Olit=all

Places string literals and constants defined with the ANSI C const type qualifier into the .rodata section. The .rodata section is used for read-only data storage. This option can reduce memory requirements and improve run-time speed in multi-user applications.

Normally the C compiler only places floating-point constant values in the .rodata section, and other constants and literals in the .data section. This option allows the placement of large data objects, such as ANSI C const arrays, into the .rodata section.

All users of an application share the static data stored in the .rodata section. Each user is allocated a private copy of the dynamic data stored in the .data section. By moving additional static data from the .data section to the .rodata section, overall system memory requirements can be reduced and run-time speed improved. Most applications can benefit from this option.

Users should not attempt to modify string literals if they use the +Olit=all option. The reason is that this option places all string literals into read-only memory. Particularly, the following C library functions should be used with care, since they can alter the contents of string literals if users specify string literals as the receiving string.

extern char *strncat(char *, const char *, size_t);
extern void *memmove(void *, const void *, size_t);
extern char *strcpy(char *, const char *);
extern char *strncpy(char *, const char *, size_t);
extern char *strcat(char *, const char *);
extern char *strtok(char *, const char *);

+FPflags

Specifies what floating-point traps to enable and also enables or disables fast underflow mode. flags is a series of upper case or lower case letters from the set [VvZzOoUuIiDd] with no spaces, tabs, or other characters between them. If the upper-case letter is selected, that behavior is enabled. If the lower-case letter is selected or if the letter is not present in the flags, the behavior is disabled. By default, all traps are disabled. The values for flags are:

V

Enable traps on invalid floating-point operations.

v

Disable traps on invalid floating-point operations.

Z

Enable traps on divide by zero. (If your program must conform to the POSIX standard, do not enable this trap.)

z

Disable traps on divide by zero.

O

Enable traps on floating-point overflow.

o

Disable traps on floating-point overflow.

U

Enable traps on floating-point underflow.

u

Disable traps on floating-point underflow.

I

Enable traps on floating-point operations that produce inexact results.

i

Disable traps on floating-point operations that produce inexact results.

 
D

Enable fast underflow (flush to zero) of denormalized values. (Enabling fast underflow is an undefined operation on PA-RISC 1.0 based systems, but it is defined on all subsequent versions of PA-RISC. Selecting this value enables fast underflow only if it is available on the processor that is used at run time.)

d

Disable fast underflow (flush to zero) of denormalized values.

To dynamically change these settings at run time, refer to fegetround(3M).

+help

Launches a web browser displaying an html version of the HP C/HP-UX online help, and then processes any other arguments. See “HP C Online Help ” for instructions on setting up your environment to view the HP C Online Help.

+Oprofile=collect

Instructs the compiler to instrument the object code for collecting run-time profile data. The profiling information can then be used by the linker to perform profile-based optimization. Code generation and optimization phases are delayed until link time by this option.

After compiling and linking with +Oprofile=collect, run the resultant program using representative input data to collect execution profile data. Profile data is stored in flow.data by default.

+M0 (or +M)

Emits ANSI C migration warnings. Use the +M option with either -Aa or -Ac. These were formerly part of +w1.
The document ANSI Programming Language C Standard ISO 9899:1990 discusses the behavioral differences in code that is migrated to ANSI C. These differences are called quiet changes.

+M1Emit warnings for possible problems connected with platform migration.
+M2Emit warnings for possible problems connected with migration to the LP64 data model (64-bit mode). This option is only available in 64-bit mode. Refer to the HP-UX 64-bit Porting and Transition Guide for details.
+Olit

This option places the data items that do not require load-time or run-time initialization in a read-only data section. is the default value.

+Olit can take these values:

all

All string literals and all const-qualified variables that do not require load-time or run-time initialization will be placed in a read-only data section. +Olit=all replaces the deprecated +ESlit option.

const

All string literals appearing in a context where const char * is legal, and all const-qualified variables that do not require load-time or run-time initialization will be placed in a read-only data section. +Olit=const is mapped to +Olit=all. +Olit=const replaces the deprecated +ESconstlit option.

none

No constants are placed in a read-only data section. +Olit=none replaces the deprecated +ESnolit option.

+[no]objdebug

When used with -g, +objdebug leaves debug information in the object files instead of copying it to the executable file at link time, resulting in shorter link times and smaller executables. The default, +objdebug, copies the debug information to the executable file.

When you specify -g, the compiler places symbolic debugging information into the object files. By default, the linker calls pxdb which compacts this debug information & copies it to the executable file. When +objdebug was used at compile time, the linker leaves the debug information in the object files. To debug the executable file, the HP WDB debugger must have access to the object files. If you move the object files, use HP WDB’s objdir command to tell it where the object files are. This option reduces link time and the size of the executable file by avoiding this copying of debug information.

The compile-time default is +noobjdebug. If the linker detects any object files that were compiled with +objdebug, it will leave the debug information in those files. Any object files not compiled with +objdebug will have their debug information copied into the executable file. You can leave debug information in some object files and not in others.

Use the +noobjdebug option when linking to explicitly tell the linker to copy all debug information to the executable file, even from files compiled with +objdebug.

+Oopt

Invokes the level of optimization selected by opt. opt can have any of the following values.

1

Performs level 1 optimizations.

2

Performs level 1 and 2 optimizations.

3

Performs level 1, 2, and 3 optimizations.

4

Performs level 1, 2, 3, and 4 optimizations.

For a complete list of advanced optimization toggles, see Chapter 4, “Optimizing HP C Programs,” in the HP C/HP-UX Programmer's Guide.

+Oprofile=use:filename

The compiler will look in filename for a profile database file. The default is flow.data. See HP C Online help for more information.

+Oprofile=collect

It is valid only with -c and for optimization levels less than O4. This option is used to improve compile time performance. See HP C Online help for more information.

+Oprofile=use

Directs the compiler to use profile information to guide code generation and profile-based optimization. This option causes the compiler to generate intermediate compiler code instead of compiled object code. The actual code generation is done at link time.

This option does not affect the default optimization level, or the optimization level specified by the -O or +Oopt options. Source files that are compiled with +Oprofile=collect option do not need to be recompiled with +profile=use in order to use profile-based optimization. You only need to relink the object files with this option after running the instrumented version of the program.

+sbUse signed bitfields (in 32- and 64-bit modes). By default, unqualified bitfield types are signed in 32-bit mode and unsigned in 64-bit mode.

+ubytes

Forces all pointer references to assume that data is aligned on either an 8-bit, 16-bit, or 32-bit addresses. bytes can be 1 (8-bit), 2 (16-bit), or 4 (32-bit). The default value for +u is 2. This option can be used when reading in non-natively aligned data. Pragmas are also available to assist with processing non-natively aligned data. See Chapter 2, “Storage and Alignment Comparisons,” in the HP C/HP-UX Programmers Guide for more information.

+uc

Makes unqualified char data types unsigned. By default, the HP C compiler makes all unqualified char data types signed. Use this option to help port applications from other vendor platforms, where the default behavior for unqualified char types is unsigned. Be careful when using this option. Your application may have trouble interfacing with HP-UX system libraries and other libraries that do not use this option.

+wn

Specifies the level of the warnings messages. The value of n can be one of the following:

  • 1—All warnings are issued. This includes low level warnings that may not indicate anything wrong with the program.

  • 2—Only warnings indicating that code generation might be affected are issued. This is equivalent to the compiler default without the -w options.

  • 3—No warnings are issued. This is equivalent to the -w option.

This option is the same as -W c,-wn.

+W n1[,n2[,...nN]]

Suppresses the specified warnings, where n1 through nN are valid compiler warning message numbers. See the file /opt/ansic/lib/nls/msg/C/cc.msgs for a list of error and warning messages.

+We n1[,n2[,...nN]]

Changes the specified warning to an error, where n1 through nN are valid compiler warning messages. See the file /opt/ansic/lib/nls/msg/C/cc.msgs for a list of compiler messages.

+Ww n1[,n2[,...nN]]

Enables the specified warnings, assuming all other warnings have been suppressed with -w or +w3. n1 through nN are valid compiler warning messages. See the file /opt/ansic/lib/nls/msg/C/cc.msgs for a list of compiler messages.

+z

Generates object code that can be added to a shared library. Object code generated with this option is position independent, containing no absolute addresses. All addresses are either pc-relative or indirect references. This is the same as the +Z option in 64-bit mode.
The -p and -G options are incompatible with this option and are ignored. See the HP-UX Linker and Libraries Online User Guide for detailed information on shared libraries.

+Z

This option is similar to +z with the difference being that space for more imported symbols is allocated. The size of the data linkage table allocated by the +z and +Z options is machine dependent. Use the +Z option when the linker ld issues an error message indicating data linkage table overflow. +Z is the default in 64-bit mode. For more information on shared libraries, see the HP-UX Linker and Libraries Online User Guide.

Any other option encountered generates a warning to standard error (stderr.) (Options not recognized by cc are not passed on to ld. Use the -Wl,arg option to pass options to ld.)

 

Examples of Compiler Commands

  • cc -Aa prog.c

    requests a strict ANSI C compilation of prog.c.

  • cc -tp,/users/devel/cpp prog.c

    uses /users/devel/cpp as the pathname for the preprocessing phase.

  • cc -tpca,/users/devel/x prog.s

    uses /users/devel/x/cpp for cpp, /users/devel/x/ctcom for ctcom, and /users/devel/x/as for as; the assembly file prog.s is processed by the specified assembler.

  • cc -Aa prog.c procedure.o -o prog

    compiles and links the file prog.c, creating the executable program file prog. The compiler produces prog.o. The linker ld(1) links prog.o and procedure.o with all of the HP C startup routines and the library routines from the HP C library /usr/lib/hpux32/libc.so.

  • cc prog.c -co /users/my/prog.o

    compiles the source file prog.c and places the object file prog.o in /users/my/prog.o.

  • cc -Wp,-H150000 p1.c p2.c p3.c -o p +legacy_cpp

    compiles the source files in the option -H150000 to the preprocessor cpp to increase the define table size from the default.

  • cc -Wl,-vt *.c -o vmh

    compiles all files in the working directory ending with .c, passes the -vt option to the linker, and causes the resulting program file to be named vmh.

  • cc -vg prog.c

    compiles prog.c, adds debug information, and displays the steps in the compilation process.

  • cc -S prog.c

    compiles the file prog.c into an assembly output file called prog.s.

  • cc -OAa prog.c

    compiles prog.c in ANSI mode and requests level 2 optimization.

  • cc +O1 prog.c

    compiles prog.c and requests level 1 optimization.

  • cc +w1 prog.c -c

    compiles prog.c with low-level warnings emitted and suppresses linking.

  • cc -D BUFFER_SIZE=1024 prog.c

    passes the option -D BUFFER_SIZE=1024 to the preprocessor, setting the value of the macro for the compilation of prog.c.

  • cc prog.c -lm

    compiles prog.c requests the linker to link the library /usr/lib/hpux32/libm.so with the object file prog.o to create the executable a.out.

  • cc -L/users/devel/lib prog.c -lme

    compiles prog.c and causes the linker to search the directory /users/devel/lib for the library libme.a, before searching in /usr/lib/hpux32.

  • cc +DD32 +Z -c prog.c

    compiles prog.c for use in a large shared library in 32-bit mode.

  • cc +DD64 +Z -c prog.c

    compiles prog.c for use in a large shared library or executable in 64-bit mode.

  • cc +DD32 +z -c prog.c

    compiles prog.c in 32-bit mode for use in a shared library with less than 16K of symbols.

  • cc +DD64 prog.c

    compiles prog.c in 64-bit mode.

    Refer to the discussion on optimization options in the C online help or the HP C/HP-UX Programmer’s Guide for more information.

Environment Variables

This section describes the following environment variables you can use to control the C compiler:

  • CCOPTS

  • TMPDIR

  • aCC_MAXERR

CCOPTS Environment Variable

You can pass arguments to the compiler using the CCOPTS environment variable or include them on the command line. The CCOPTS environment variable provides a convenient way for establishing default values for cc command line options. It also provides a way for overriding cc command line options.

The syntax for the CCOPTS environment variable in C shell notation is:

export CCOPTS="options | options" (ksh/sh notation)

setenv CCOPTS "options | options" (csh notation)

The compiler places the arguments that appear before the vertical bar in front of the command line arguments to cc. It then places the second group of arguments after any command line arguments to cc.

Options that appear after the vertical bar in the CCOPTS variable override and take precedence over options supplied on the cc command line.

If the vertical bar is omitted, the compiler gets the value of CCOPTS and places its contents before any arguments on the command line.

For example, the following in C shell notation

setenv CCOPTS -v
cc -g prog.c

is equivalent to

cc -v -g prog.c

For example, the following in C shell notation

setenv CCOPTS "-v | +O1"
cc +O2 prog.c

is equivalent to

cc -v +O2 prog.c +O1

In the above example, level 1 optimization is performed, since the +O1 argument appearing after the vertical bar in CCOPTS takes precedence over the cc command line arguments.

TMPDIR Environment Variable

Another environment variable, TMPDIR, allows you to change the location of temporary files that the compiler creates and uses. The directory specified in TMPDIR replaces /var/tmp as the default directory for temporary files. The syntax for TMPDIR in C shell notation is:

export TMPDIR=directory (ksh/sh notation)

setenv TMPDIR directory (csh notation)

directory is the name of an HP-UX directory where you want HP C to put temporary files during compilation.

aCC_MAXERR Environment Variable

This release of HP C compiler provides support to specify the maximum number of errors emitted before the compilation aborts. In the earlier versions, the compiler stopped, if it recognized more than 99 errors while compiling. With this release, the maximum number of errors that the compiler emits can be tuned as required by setting the aCC_MAXERR environment variable.

The syntax for aCC_MAXERR in C shell notation is:

export aCC_MAXERR=errors

where errors are the maximum number of errors set.

SDK/XDK

SDK/XDK, helps you in selecting the components, headerfiles, and libraries installed in alternate locations. To enable this support in your compiler, you need to set either one or both of the following environment variables:

  • SDKROOT

  • TARGETROOT

Setting SDKROOT Environment Variable

The SDKROOT environment variable is used as a prefix for all references to tool set components. This environment variables is set by the user while using a non-native development kit or toolset installed at an alternative location. Some of the toolset components are compiler drivers, compiler applications, preprocessor, linker, and object file tools. If the HP C compiler has its tool set installed in /opt/xdk-pa/directory then the command:

export SDKROOT=/opt/xdk-pa

will prefix all references to the HP C compiler tool set components with /opt/xdk-pa. The following details the default tool set components location as specified in the above command and its earlier location before the execution of the command:

Table 9-3 Title not available (Setting SDKROOT Environment Variable)

Native locationAlternate toolset location
/opt/ansic/bin/cc/opt/xdk-pa/opt/ansic/bin/cc
/opt/ansic/lbin/ctcom/opt/xdk-pa/opt/ansic/lbin/ctcom
/opt/langtools/lbin/cpp.ansi/opt/xdk-pa/opt/langtools/lbin/cpp.ansi
/opt/ansic/lbin/u2comp/opt/xdk-pa/opt/ansic/bin/u2comp

 

Invoking the tool set components will actually result in the invocation of tool set components from the alternate location as specified above.

Setting TARGETROOT Environment Variable

The TARGETROOT environment variable is used as a prefix for all references to target set components. This environment variable is set by the user when using a non-native development kit. Some of the target set components are header files, archive libraries, and shared libraries. If the HP C compiler has its large tool set installed in /opt/xdk-pa/directory, the command:

export TARGETROOT=opt/xdk-pa

will prefix all references to the target tool set components with /opt/xdk-pa. The following details the default location of the tool set components as specified in the above command and its earlier location before the execution of the command:

Table 9-4 Title not available (Setting TARGETROOT Environment Variable)

Native locationAlternate toolset location
/usr/include/opt/xdk-pa/usr/include
/usr/lib/opt/xdk-pa/usr/lib

 

NOTE: Options like -l or -L on the command line will override $TARGETROOT prefixing.
© Hewlett-Packard Development Company, L.P.