Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
HP.com home

Compaq C++ User Documentation


Compaq C++

Compaq C++
Using Compaq C++ for Tru64 UNIX and Linux Alpha

Previous Contents Index

Chapter 1
Building and Running C++ Programs

This chapter provides information about the basic steps involved in developing a Compaq C++ program. It explains how to compile, link, and debug programs.

Compaq C++ is an implementation of the C++ programming language. The compiler is part of the Compaq Tru64 UNIX and Linux Alpha compiler systems. See the Compaq Tru64 UNIX and Linux Alpha Programmer's Guide for program development information that applies to all Compaq Tru64 UNIX and Linux Alpha languages, such as using the compiler system, creating shared libraries, profiling, and optimization.

1.1 Compiling a Program

The cxx command invokes the compiler. For information about using the cxx (Compaq C++ compiler) command, including a description of command options, refer to the cxx(1) reference page. For information about this release, see the Compaq C++ Release Notes for Tru64 UNIX .

You can compile a mixture of C++ and C source code by entering a single cxx compile command. The compiler distinguishes between C++ source files (for example, .cxx ) and C source files (for example, .c ) based on their file extensions, and it compiles the modules appropriately.

Unless you use the -x option to direct the compiler to ignore file-name extensions, passing a file with a .c extension to the cxx command causes the compiler driver to treat the file as a C file and pass it on to the cc command on Tru64 UNIX or the ccc command on Linux Alpha . If the file contains C++ code instead of C code, the compilation might produce errors.

1.2 Linking a Program

Always use the cxx command to link your programs. Linking through the cxx command ensures that all the necessary link options are passed to the ld linker. If your program is not linked properly, some static objects will not be initialized at program startup. If a module is built using Version 6.n, it must be linked with the Version 6.n library.

If you choose to use the ld linker directly, you might need to modify your ld command whenever you install a new version of the compiler or the Compaq Tru64 UNIX and Linux Alpha operating system. After the installation, follow these steps:

  1. Invoke the cxx command and specify the -v option to display the ld command in use.
  2. Compare this ld command with your ld command and make any necessary changes.

If you are using templates, you must modify the ld command by replacing the -input argument with a list of your template instantiation object files. The replacement string is normally cxx_repository/*.o .

To use automatic template instantiation, you must link with cxx .

See the cxx(1) and the ld(1) reference pages for more information.

1.3 Name Demangling

The C++ compiler encodes type information in function names to enable type-safe linkage. This encoding is called name mangling. Function name mangling allows object code to have distinct names for functions that share the same name in the C++ source code and enables type-safe linkage.

It is often difficult to decipher mangled names that might appear in diagnostic messages from system tools such as the ld linker. A name demangler is provided to translate such mangled names into the function names that appear in the source code, so that they are recognizable by the user.

You can use either the cxx command or the demangle command to help interpret mangled messages from the linker. If you use the cxx command to invoke the linker, the compiler pipes any linker output to the name demangler unless you specify the -nodemangle option.

The demangle command reads each file in sequence, demangles any names encoded by the compiler, and displays the results on the standard output device. See the demangle(1) reference page for more information.


demangle [-show_mangled_name][-no_vtable_info][-][file...] 

If no input file is given, or if a minus sign is encountered as an argument (for example, demangle - ), the demangle command reads from the standard input file. The demangle utility supports the processing of 8-bit characters.


- Read from the standard input file.
-show_mangled_name Display encoded name in parentheses after demangled name.
-no_vtable_info Suppress the display of information concerning internal symbols (specifically __vtbl and __btbl ).


demangle file

This command demangles a file containing Compaq C++ encoded names.

ld main.o foo.o |& demangle 

This command (from the C shell) demangles the output from the linker ( ld ) when linking the main.o and foo.o files.

1.4 C++ Standard Library

The C++ Standard Library defines a complete specification of the International C++ Standard, with some differences, as described in the Compaq C++ Release Notes for Tru64 UNIX .

Some of the components in the C++ Standard Library are designed to replace nonstandard components that are currently distributed in the C++ Class Library. However, Compaq will continue to provide the C++ Class Library. Note that on Linux Alpha, the Class Library task package in not supported.

On Tru64 UNIX, the Class Library task package will gradually be retired. Starting with Version 6.3 of the compiler, the task library is no longer distributed in the shared format.

Linking to the Standard Library

When you use the cxx command to compile and link programs that use the C++ Standard Library, no special switches are required. The C++ driver automatically includes the Standard Library run-time support ( -lcxxstd ) on the link command, and automatic template instantiation ( -pt ) is the default mode.

For example, to build a program called prog.cxx that uses the Standard Library, you enter the following command:

cxx prog.cxx 

For detailed information about the Standard Library, refer to Chapter 7.

1.5 C++ Class Library

Reusing code is a cornerstone of object-oriented programming. To minimize the time it takes to develop new applications, a set of reusable classes is an essential part of Compaq C++. Class libraries offer a variety of predefined classes that enable you to work more efficiently.

See the C++ Class Library Reference Manual . for a detailed explanation of the Class Library packages supplied with the compiler. The iostream class library package is from AT&T. See The AT&T C++ Language System, Release 2.0, Library Manual for a description of this package.

Linking to the C++ Class Library

Most of the C++ Class Library packages are automatically included in your program when needed. However, when using the complex package, you must provide the following explicit information for the linker:

-lcomplex -lm 

[Tru64] To use the task package, specify the following when linking using the cxx command:

-threads -ltask 

For example:

cxx thread_program.cxx -threads -ltask 

If you link using the -non_shared option to the cxx command, you must also specify -lcmalib . For example:

cxx -non_shared thread_program.cxx -threads -ltask -lcmalib 

These and other Class Library packages are documented in the C++ Class Library Reference Manual.

1.6 Linking With Non-Default Libraries

When you use the cxx command to compile and link programs that use symbols not found in the default libraries, you must explicitly link your program with the library that contains those symbols. Link the libraries by specifying -lstring, where string is an abbreviation of the library name. Failure to do so will result in unresolved symbols at link time.

Consider the following program, sqrt_example.cxx :

// sqrt_example.cxx 
#include <math.h> 
int main() { 
  double d = 3.14; 
  d = sqrt(d); 
  return 0; 

If you enter the command cxx sqrt_example.cxx to compile the program, the following error appears at link time:


You can use the cxx driver to resolve the symbol "sqrt" found in the math library libm.a by entering the following command:

cxx sqrt_example.cxx -lm 

Invoking the man command with the unresolved symbol as an argument usually provides clues to help you find the name of the library that contains the symbol.

1.7 Debugging

The Ladebug Debugger is a source-level debugger that supports Compaq C++. Neither the dbx nor the gdb debugger supports debugging C++ programs. For details on using the Ladebug Debugger, see Chapter 9.

1.8 Improving Build Performance

This section contains suggestions for improving build performance when using Compaq C++ on your system.

1.8.1 Object File Compression [Tru64]

By default, the compiler compresses object files. This reduces object file size and can result in shortened link times, depending on characteristics of the system and the application. For some large applications, object file compression can significantly slow down the compiler and the linker and can significantly increase the amount of virtual memory required when linking. For some large applications, it is advantageous to compile without object file compression. To do so, specify the -nocompress option on the cxx command.

1.8.2 Using Shared Libraries

Partitioning a large application into several shared libraries, which are then linked into an executable, is a useful technique for reducing link times during development. See Chapter 3 for details.

1.8.3 Using Precompiled Headers

Using precompiled headers can reduce compilation time in environments where

  • Many primary sources include the same set of headers in the same order.
  • These headers introduce many lines of code.

See Chapter 6 for details.

1.8.4 Performance Optimization Options

For a description of performance optimization options, see the cxx(1) reference page.

1.9 Deploying Your Application [Tru64]

Applications developed using the Compaq C++ compiler require functionality provided in the C++ Run-Time Library. While this run-time library ships with the Tru64 UNIX operating system, newer versions are released with each new version of the compiler. These newer versions provide bug fixes and support for new features in the compiler.

The C++ library redistribution kit gives the user the oportunity to upgrade the C++ library to the most up-to-date libraries without having to upgrade the entire OS and alleviates the need for application developers to include it in their distributions. Because the library is built to be upwardly compatible, a later version of the library works with applications developed by all prior versions of the compiler.

While we strongly recommend upgrading for bug fixes, this is not mandatory. Read the compiler Release Notes to determine whether your application depends on these bug fixes.

Upgrading for new compiler feature support is not optional. To run an application developed using verion n of the compiler, you must use a version of the library that provides support for all its features. In previous versions, this typically results in undefined symbol errors from the loader at runtime. Starting in V6.3, failure to do so will result in the following diagnosic from the loader at runtime:

slab> a.out 
333677:a.out: /sbin/loader: Fatal Error: object libcxx.so from liblist in a.out 
has version "cxx6.3", which does not match the found object: libcxx.so (with 
version ":V4.0.1") 

The following table provides the version of the library that shipped with each version of the OS. The C++ Compiler Feature Version is the absolute highest version of the compiler with which an application could have been developed and be deployed on this platform without the redistribution kit. An application developed with a newer compiler or that depends on a bug fix requires the installation of the redistribution kit.

OS Default C++ Library
Shipped with System
Highest Version of C++ Compiler
Not Requiring Redistribution Kit
4.0D 6.0-021 6.1-031
4.0E 6.0-021 6.1-031
4.0F 6.1-031 6.1-031
4.0G 6.2-037 6.2-040
5.0 6.2-024 6.2-040
5.0A 6.2-037 6.2-040
5.1 6.2-037 6.2-040
5.1A 6.3-001 6.5-nnn
NEXT 6.3-001 6.5-nnn
TBD 6.5-nnn 6.5-nnn

1.9.1 Redistributing the C++ Run-Time Library

If you are a third-party vendor who is shipping a product based on Version 6.5 or later, you must ensure your that your customers have a V6.3 or later C++ Run-Time Library. To do so, you can direct them to download the latest redistribution kit from the Compaq C++ web site , or you can redistribute it under conditions stated in the Software Product Description .

The mechanism for redistributing the library is for you to provide the file


mm is the revision numbers for this release. This tar file contains a setld kit that installs /usr/lib/cmplrs/cxx/version/libcxx.so and places a symbolic link in /usr/lib/cmplrs/cxx to the latest runtime installed on the system.

1.9.2 Instructions for Installing Redistribution Kit

To install the kit, follow these steps:

  1. Check if the installed libcxx is earlier than the one on this redistribution kit
    Newer libcxx.so images have symbols defined which identify the version of the run-time library. If the symbol __libcxx_V60500001 exists in the image on your system, then you do not need to install this kit.

       # nm /usr/lib/cmplrs/cxx/libcxx.so | grep libcxx_V 
       __libcxx_V60200002    | 0004396996916008 | G | 0000000000000000 
       __libcxx_V60200003    | 0004396996916016 | G | 0000000000000000 
       __libcxx_V60300001    | 0004396996918728 | G | 0000000000000000 
       __libcxx_V60500001    | 0004396996920176 | G | 0000000000000000 
  2. If an older redistribution kit was previously installed on the system, it must be removed prior to the installation of the new one.
    The subset name could be CXXLIBnnn or CXXREDISTnnn

       # /usr/sbin/setld -i | egrep "CXXLIB|CXXREDIST" | grep install 
       CXXREDIST610   installed  Compaq C++ Run-Time Library ... 
       # /usr/sbin/setld -d CXXREDIST610 
  3. Install the redistribution kit

       # tar -xvf CXXREDIST650Vmm.tar 
       # /usr/sbin/setld -l CXXREDIST650.kit 

1.10 Using OpenMP

The compiler supports C/C++ OpenMP Version 1.0. C++ exception handling within an OpenMP parallel region is not initially supported but will be supported in a later release. By default, the compiler ignores all C++ OpenMP directives unless you specify the -omp option. For example:

cxx -omp omp_program.cxx 

Previous Next Contents Index
About PDF files: The PDF files on this site can be read online or printed using Adobe® Acrobat® Reader. If you do not have this software on your system, you may download it from Adobe's website.
Privacy statement Using this site means you accept its terms C++ support
© 2008 Hewlett-Packard Development Company, L.P.