United States |
![]() |
![]() |
|
Previous | Contents | Index |
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:
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 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.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 [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.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
For a description of performance optimization options, see the
cxx(1)
reference page.
1.8 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. Failure to do so typically results in undefined symbol errors from the loader at runtime.
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.
The current redistribution kit, CXXREDIST630V01.tar, contains files that will not appear until a future release of the Tru64 UNIX operating system.
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 |
TBD | 6.3-001 | 6.3-001 |
If you are a third-party vendor who is shipping a product based on Version 6.2 or later, you must ensure your that your customers have a Version 6.2 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
/usr/lib/cmplrs/cxx/version/CXXREDISTnnnVmm.tar |
where nnn is 630 and mm is 02.
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.8.2 Instructions for Installing Redistribution Kit
To install the kit, follow these steps:
# 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 |
# /usr/sbin/setld -i | egrep "CXXLIB|CXXREDIST" | grep install CXXREDIST630 installed Compaq C++ Run-Time Library ... # /usr/sbin/setld -d CXXREDIST620 |
# tar -xvf CXXREDIST630V02.tar # /usr/sbin/setld -l CXXREDIST630.kit |
The compiler supports C/C++ OpenMP Version 1.0. By default, the compiler ignores all C++ OpenMP directives unless you specify the -omp option. Note that C++ exception handling within a parallel region is not supported in this release.
Previous | Next | Contents | Index |
![]() |
![]() |