search    
HP aC++ Online Programmer's Guide
Hewlett-Packard
Compiler Command Syntax and Environment Variables
This section introduces you to the the HP aC++ compiler command syntax and environment variables. It discusses the following topics:
Compiler Command Syntax
The aCC command (the driver) invokes the HP aC++ compiling system. Syntactically, the aCC command is followed by options and files that need to be compiled.
aCC [options] [files]
You must use the aCC command to link your HP aC++ programs and libraries. This ensures that all libraries and other files needed by the linker are available.

Example:

aCC prog.C
This command compiles the source file prog.C and puts the executable code in the file a.out.

Files on The aCC Command Line
Files on the aCC command line can be one or more files containing source or object code to be compiled or linked. These files can be:
C++ Header Files
Typically, header files are referenced in C++ source files using the #include preprocessor directive.


C++ source files (.C files)
HP aC++ source files must be named with extensions beginning with either .c or .C, possibly followed by additional characters.

If you compile only, each C++ source file produces an object file with the same file name prefix as the source file and a .o file name suffix. However, if you compile and link a single source file into an executable program in one step, the .o file is automatically deleted.


Note: It is recommended that your source files have extensions of .c or .C only, without additional characters. While file extensions other than .c or .C are permitted for portability from other systems, other endings may not be supported by HP tools and environments.

Preprocessed source files (.i files)
Files with names ending in .i are assumed to be preprocessor output files. Files ending in .i are processed the same as .c or .C files, except that the preprocessor is not run on the .i file before the file is compiled.

Use the -P or the -E compiler option to preprocess a C++ source file without compiling it.


Assembly language source files (.s files)

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

Use the -S option to compile a C++ source file to assembly code and put the assembly code into a .s file.


Object files (.o files)

Files with .o extensions are assumed to be relocatable object files that are to be included when linking.

The compiler invokes the linker to link the object files and produce an executable file.

Use the -c option to compile a C++ source file into a .o file.


Library files (.sl or .a files)

Files ending with .a are assumed to be archive libraries. Files ending with .sl are assumed to be shared libraries.

Use the -c and +z options to create object files of position-independent code (PIC) and the -b option to create a shared library.

Use the -c option to create object files and the ar command to combine the object files into an archive library.


Examples of the aCC Command
Following are some more examples of the aCC command:
  • Compiling and Renaming the Output File:
    aCC -o prog prog.C
    Compiles prog.C and puts the executable code in the file prog, rather than in the default file a.out.
  • Compiling and Debugging:
    aCC -g prog.C
    Compiles prog.C and includes information allowing you to debug the program with the HP WDB Debugger, wdb.

  • Compiling Without Linking:
    aCC -c prog.C
    Compiles prog.C and puts the object code in the file prog.o. It does not link the object file and does not create an executable file.

  • Linking Several Object Files:
    aCC file1.o file2.o file3.o
    Links the listed object files and puts the executable code in the file a.out.
    Note: You must use the aCC command to link your HP aC++ programs and libraries. This ensures that all libraries and other files needed by the linker are available.

  • Processing Multiple Options by Specifying a Filename:
    aCC +opts filename
    Allows processing of multiple options by specifying only the name of the file (indicated by filename), which contains a list of the options to be processed. These options will be executed as if they had been specified at the command line after the the +opts option.

  • Compiling, Optimizing, and Getting Verbose Information:
    aCC -O -v prog.C
    Compiles and optimizes prog.C, gives verbose progress reports, and creates an executable file a.out.

  • Compiling and Creating a Shared Library:
    
    aCC +z -c prog.C
    
    aCC -b -o mylib.sl prog.o
    
    
    The first line compiles prog.C, creates the object file prog.o, and puts the position-independent code (PIC) into the object file. The second line creates the shared library mylib.sl, and puts the executable code into the shared library.

Environment Variables
You can use the following environment variables with HP aC++:
  • aCC_FULL_PATHNAMES
  • CXXOPTS - Specify command line options automatically.
  • CCLIBDIR - Specify additional directories for the linker to search for libraries.
  • CCROOTDIR - Use this when compiler subprocesses are in alternate directories.
  • TMPDIR - Change the location of temporary files that the compiler creates.
  • LC_CTYPE - Sets C as the value for any internationlization variable not set.
  • aCC_MAXERR -Sets the maximum number of errors that the compiler can report.
  • SDKROOT - Sets an alternative path for the development tool kit.
  • TARGETROOT- Sets an alternate path for the target set components.
  • CXX_MAP_FILE - Sets the path of the option-mapping file.
  • CXX_CONFIG - Sets the path of the configuration file.

aCC_FULL_PATHNAMES Environment Variable
Exporting the aCC_FULL_PATHNAMES variable causes the compiler to include full path names for files in compiler messages. This feature is useful in debugging.


CXXOPTS Environment Variable

CXXOPTS provides a convenient way to include frequently used command line options automatically.

Set the environment variable and the options you want are automatically included each time you execute the aCC command.

Syntax:


export CXXOPTS="options | options"   ksh notation

setenv CXXOPTS "options | options"   csh notation

Options before the vertical bar (|) are placed before command line options to aCC. Options after the vertical bar are placed after any command line options. Note that the vertical bar must be delimited by white space.

If you do not use the vertical bar, all options are placed before the command line parameters.

Usage:

For quick or temporary changes to your build environment, you might use CXXOPTS instead of editing your makefiles.

Example:


export CXXOPTS="-v | -lm" ksh notation        

setenv CXXOPTS "-v | -lm" csh notation

The above command causes the -v and -l options to be passed to the aCC command each time you execute it.

When CXXOPTS is set as above, the following two commands are equivalent:


aCC -g prog.C



aCC -v -g prog.C -lm


CCLIBDIR Environment Variable

CCLIBDIR causes the aCC command to search for libraries in an alternate directory before searching in the default directory, /opt/aCC/lib.

Syntax:


export CCLIBDIR=directory   ksh notation

setenv CCLIBDIR directory   csh notation

directory is an HP-UX directory where you want HP aC++ to look for libraries.

Example:

export CCLIBDIR=/mnt/proj/lib
In this example, HP aC++ searches the directory /mnt/proj/lib for libraries, before searching the directory /opt/aCC/lib. When CCLIBDIR is set as above, the following two commands are equivalent:

aCC -L/mnt/proj/lib file.o



aCC file.o


Note: Use the -Ldirectory option to specify additional directories for the linker to search for libraries.


CCROOTDIR Environment Variable

The CCROOTDIR environment variable causes aCC to invoke all subprocesses from an alternate aCC directory, rather than from their default directory. The default aCC root directory is /opt/aCC.

Syntax:


export CCROOTDIR=directory   ksh notation

setenv CCROOTDIR directory   csh notation

directory is an aCC root directory where you want the HP aC++ driver to look for subprocesses.

Example:

export CCROOTDIR=/mnt/CXX2.1
In the above example, HP aC++ searches the directories under /mnt/CXX2.1 (/mnt/CXX2.1/bin and /mnt/CXX2.1/lbin) for subprocesses rather than their respective default directories.


TMPDIR Environment Variable

The TMPDIR environment variable allows you to change the location of temporary files created by the compiler. The default directory is /var/tmp.

Syntax:


export TMPDIR=directory   ksh notation

setenv TMPDIR directory   csh notation

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

Example:


export TMPDIR=/mnt/temp   ksh notation

setenv TMPDIR /mnt/temp   csh notation

The above example specifies that HP aC++ should put all temporary files in /mnt/temp.


LC_CTYPE Environment Variable

The LC_CTYPE environment variable determines the interpretation of string literals and comments as single and/or multi-byte characters.

If LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, aCC behaves as if all internationalization variables are set to "C". See environ(5).


aCC_MAXERR Environment Variable

aCC_MAXERR allows you to set the maximum number of errors you want the compiler to report before it terminates compilation.


SDKROOT Environment Variable

SDKROOT is used as a prefix for all references to tool set components and must be set when you use a non-native development kit or a toolset installed at an alternative location. Some of the toolset components are compiler drivers, Compiler Applications, Preprocessor, Linker, and object file tools.

For more information, refer to the HP-UX Software Development Kit User's Guide.


TARGETROOT Environment Variable

TARGETROOT is used as a prefix for all references to target set components and must also be set when using a non-native development kit. Some of the target set components are header files, archive libraries, and shared libraries.

For more information, refer to the HP-UX Software Development Kit User's Guide.


CXX_MAP_FILE Environment Variable

The option mapping support facilitates easy migration of build environment from a different compiler to HP aC++. You can use the option mapping files to map the options in the third party compilers to HP aC++ equivalents.

Mapping File

The mapping file is a text file that defines the mapping rules. The compiler reads the mapping file and applies the specified replacements to the options on the command line. This minimizes the need to make Makefile or script changes. By default, the path for the mapping file is set to the following location:


/opt/aCC/lib/option.map

You may either define the mapping rules in this file or set the mapping file path to an alternate location. To specify an alternate location, set the CXX_MAP_FILE environment variable, like the following example:


export CXX_MAP_FILE=/home/src/my_option.map   sh/ksh notation

setenv CXX_MAP_FILE /home/src/my_option.map   csh notation

where:
my_option.map is the name of the new mapping file.

To disable the use of the mapping file (inspite of having one in the default location), set the above environment variable to NULL, like the following example:


export CXX_MAP_FILE=       sh/ksh notation

export CXX_MAP_FILE=""     sh/ksh notation

setenv CXX_MAP_FILE ""      csh notation

Defining the Mapping Rules

Following is the syntax for defining the rules in the mapping file:


LHS => RHS  (Note the space before and after '=>')

Where:
LHS is the third party compiler option
RHS is the HP aC++ compiler option

To define rules for options that have arguments, use the $number wildcard. For example, $1 for the first argument, and $2 for the second. If the third party compiler option (LHS) does not match with any HP aC++ option, leave the RHS blank.

Example Rules

The following example rules map gcc compiler options to corresponding HP aC++ compiler options. The same rules can be used for mapping options from any third party compiler. The syntax for the rule becomes as follows:


gcc_option => hp_option 

  • -Wtraditional =>
      Ignores (removes) -Wtraditional, a gcc option from the command line.
  • -shared => -b
      Replaces -shared with -b at the command line.
  • -rpath-link $1 =>
      Deletes -rpath-link and the arguments from the command line.
  • --gccopt $1=$2 => -hpopt $2
      Replaces --gccopt name at the command line with -hpopt name.
  • -gccopt $1 => +xyz
      Replaces -gccopt optionarg at the command-line with +xyz.
  • -Bstatic => -a archive -noshared
     Replaces -Bstatic with -a archive noshared.


CXX_CONFIG Environment Variable

You can specify default sitewide options for HP aC++ in a configuration file. On startup, HP aC++ reads, and applies the default options from the file if the file is found and readable. No default options are set if the file is not found or readable.

The default path of the configuration file is set to the following locations:


/var/aCC/share/aCC.conf         in C++ mode

/var/ansic/share/cc.conf        in C mode

To change the path of the configuration file, use the following environment variables:


export CXX_CONFIG=newfilepath.conf sh/ksh notation    in C++ mode

setenv CXX_CONFIG newfilepath.conf csh notation



export CC_CONFIG=newfilepath.conf sh/ksh notation     in C mode

setenv CC_CONFIG newfilepath.conf csh notation   

The options in the configuration file can be specified in the following format:


[options-list-1][|[options-list-2]]

Where:
options-list-1 is applied before the options in the command line
options-list-2 is applied after the options in the command line

The final option ordering is as follows:


file-options-1 envvar-options-1 commandline-options envvar-options-2 file-options-2

Note: No default configuration files are shipped with HP aC++. The system administrator can create them, if required.


International Code Set Support

Supports Single- and multi-byte character code sets.

Floating Installation
More than one version of the HP aC++ compiler can be installed on one system at the same time. The floating installation feature allows you to install the compiler in any location. You can install as many compiler versions as required, depending on your system's resources.

By default, HP aC++ is installed under the /opt/aCC directory. In earlier releases, the compiler driver (aCC) looked for related files in subdirectories of /opt/aCC. This prevented installation of more than one version of HP aC++ on the same system at the same time.

Note that only the files in /opt/aCC are affected by floating installation. No matter which HP aC++ driver you are using, the compiler still uses the libraries, linker, and other files located in /usr/lib and /usr/ccs.

Floating installation is designed to help facilitate in-house development. Be aware that you must not ship libraries in non-standard places, since explicit run-time library specifications and linker options are required.


Note: You can use the __HP_aCC predefined macro to determine which version is being run.

Floating installation is not intended for use with the following:

Setting Up Floating Installation
You may want to install the most recent compiler version and keep the prior version on one system. If there are problems with the most recent version, it is easy to switch to the prior one. Following is an example of how to set up the floating installation feature for this purpose.

Assume that your system will have two versions of the compiler, both floating install enabled. In this case, A.03.10 is the prior version, and A.03.13 is the more recent version.

  1. Copy the prior version to another directory.
    cp -rp /opt/aCC /opt/aCC.03.10

  2. Use swinstall to install the new version (in this case, A.03.13).

  3. Invoke the A.03.10 compiler with its absolute path using the following command:
    /opt/aCC.03.10/bin/aCC app.C
    Alternatively, you can change your PATH environment variable or set up an alias for the absolute path.

  4. To invoke the A.03.13 compiler, use the following command:
    aCC app.C

The HP aC++ driver accesses subprocesses for the version you invoke.

If you want to floating install a newer compiler, use swinstall to install the compiler to an alternate root:

  1. swinstall .... @ /opt/aCC.03.13
  2. Invoke the A.03.13 compiler with its absolute path: /opt/aCC.03.13/opt/aCC/bin/aCC app.c
Alternatively, you can change your PATH environment variable or set up an alias for the absolute path.