United States    
COMPAQ STORE | PRODUCTS | SERVICES | SUPPORT
| CONTACT US | SEARCH
cxxtitle.gif (12116 bytes)
Compaq C++

Compaq C++
Using Compaq C++ for Tru64 UNIX


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 on a Compaq Tru64 UNIX system. 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 compiler system. See the Compaq Tru64 UNIX Programmer's Guide for program development information that applies to all Compaq Tru64 UNIX 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. If the file contains C++ code instead of C code, the compilation might produce errors.

1.2 Linking a Program

The compiler uses cc to invoke the ld linker to generate code. Always use the cxx command to invoke the linker.

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 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.

Syntax


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.

Options
- 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 ).

Examples


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.


cxx foo.cxx |& demangle 

This command (from the C shell) demangles the output from the linker when it is invoked implicitly through the cxx command to compile foo.cxx.

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.

Because the standardization process for the C++ Standard Library is not yet completed, Compaq cannot guarantee that this version of the library is compatible with any past or future releases. For this reason, Compaq ships the run-time portion of the library in object rather than shareable form.

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 

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 Debugging

The Ladebug Debugger is a source-level debugger developed to support Compaq C++. The dbx debugger does not support debugging C++ programs. For details on using the Ladebug Debugger, see Chapter 9.

1.7 Improving Build Performance

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

1.7.1 Object File Compression

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.7.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.7.3 Using Precompiled Headers

Using precompiled headers can reduce compilation time in environments where

See Chapter 6 for details.

1.7.4 Performance Optimization Options

The compiler provides the following performance optimization options:

-[no]ansi_alias

Specifies whether the compiler assumes the ANSI C aliasing rules to generate better optimized code.

With the current version, if a program does not access the same data through pointers of a different type (and for this purpose, signed and qualified versions of an otherwise same type are considered to be the same type), then assuming ANSI C aliasing rules allows the compiler to generate better optimized code.

If a program does access the same data through pointers of a different type (for example, by a "pointer to int" and a "pointer to float"), you must not allow the compiler to assume ANSI C aliasing rules, because these rules can result in the generation of incorrect code.

Per the C++ language rules, the default is -ansi_alias.

-assume [no]pointers_to_globals

Controls whether the compiler can safely assume that global variables have not had their addresses taken in code that is not visible to the current compilation.

The default is -assume pointers_to_globals, which directs the compiler to assume that global variables have had their addresses taken in separately compiled modules and that, in general, any pointer dereference could be accessing the same memory as any global variable. This is often a significant barrier to optimization.

While the -ansi_alias option allows some resolution based on data type, -assume pointers_to_globals provides significant additional resolution and improved optimization in many cases.

The -assume pointers_to_globals option tells the compiler that any global variable accessed through a pointer in the compilation must have had its address taken within that compilation. The compiler can see any code that takes the address of an extern variable. If it does not see the address of the variable being taken, the compiler can assume that no pointer points to the variable.

Note that -assume pointers_to_globals does not tell the compiler that the compilation never uses pointers to access global variables.

-assume [no]whole_program

Tells the compiler that except for "well-behaved library routines", the whole program consists only of the single object module being produced by this compilation. The optimizations enabled by -assume whole_program include all those enabled by -assume nopointer_to_globals and possibly other optimizations.

The default is -assume nowhole_program.

1.8 Deploying Your Application

Code generated by the Version 6.n compiler requires a newer version of the C++ Run-Time library (libcxx) than is provided by Compaq Tru64 UNIX Versions prior to 4.0F.

1.8.1 Using Compaq C++ on Compaq Tru64 UNIX Version 4.0F or Later

On Compaq Tru64 UNIX 4.0F or later, the version of libcxx.so required for use with Compaq C++ Version 6.n is installed by the operating system; no special actions are required.

1.8.2 Using Compaq C++ on DIGITAL UNIX Version 4.0E or Earlier to Link and Run Programs

On Version 4.0E or earlier, you must install the following subset from the Compaq C++ Version 6.n kit before you can link or execute programs:


 Compaq C++ Run-Time Library (libcxx) for DIGITAL UNIX V4.0E and earlier 

If you attempt to link code generated by Compaq C++ Version 6.n before installing the compiler or this subset, the link might fail because of unresolved symbols.

This subset (or the compiler kit) also must be installed on any Version 4.0E or earlier system on which you want to execute code generated by Compaq C++ Version 6.n. If you attempt to execute a program without having installed the subset or compiler, the image activator displays error messages about unresolved symbols.

Note that you can install the libcxx subset without installing the base compiler subset.

1.8.3 Redistributing libcxx.so

With C++ Version 6.2-FT2, some of the functions needed for the ANSI language features (rtti, standard operator new, exceptions) have been moved from the archive library libcxxstd.a to the shared library libcxx.so.

If you are a third-party vendor who is shipping a product based on Version 6.2-FT2, you must ensure your that customers have a Version 6.2-FT2 libcxx.so. You can redistribute libcxx.so under conditions stated in the Software Product Description.

The mechanism for redistributing libcxx.so is for you to provide the .tar file /usr/lib/cmplrs/cxx/CXXREDISTnnnVmm.tar (where nnn is 620 and mm is 01. This tar file contains a setld kit that installs /usr/lib/cmplrs/cxx/libcxx.so. You should also provide the following instructions for installing libcxx.so from the tar file:

  1. Check which CXX subsets are installed:


    setld -i | grep CXX | grep installed 
    

    If either subset CXXBASEnnn or CXXREDISTnnn is installed, there is no need to install from CXXREDISTnnnVmm.tar.

  2. Untar the file by entering the following command:


    tar xvf /usr/lib/cmplrs/cxx/CXXREDIST620V01.tar 
    

    This command creates a setld kit for installing libcxx.so in directory CXXREDIST620.kit.

  3. Log in as superuser.
  4. Install by entering the following command and selecting the subset displayed:


    /usr/sbin/setld -l CXXREDIST620.kit 
    


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement