United States |
Previous | Contents | Index |
This chapter provides information about the basic steps involved in developing a Compaq C++ program on a Tru64 UNIX system. It explains how to compile, link, and debug Compaq C++ programs.
Compaq C++ is an implementation of the C++ programming language. The
Compaq C++ compiler is part of the Tru64 UNIX compiler system. See
the Tru64 UNIX Programmer's Guide for program development
information that applies to all Tru64 UNIX languages, such as using
the compiler system, creating shared libraries, profiling, and
optimization.
1.1 Compiling a Compaq C++ Program
The cxx command invokes the Compaq C++ compiler. For a full description of the cxx command, see Using the Compaq C++ Compiler in this chapter, or the cxx(1) reference page. For additional information about this release, see the online release notes in:
/usr/lib/cmplrs/cxx/DECCXXnnn.release-notes |
You can compile a mixture of C++ and C source code by entering a single cxx compile command. The Compaq C++ compiler distinguishes between C++ source files (for example, .cxx ) and C source files (for example, .c ) based on their file extensions, and compiles the modules appropriately.
Unless you use the -x option to direct the Compaq C++ 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 may produce errors.
The cxx command invokes the Compaq C++ compiler, and possibly other components of the compiler system, depending on the specified command options and files. When you start the cxx compiler, it normally performs the following tasks:
The cxx command compiles C++ code into machine-readable instructions. The desired output is specified with an option on the command line, and can be object files or symbolic assembly language.
The compiler produces one object file for each file that is compiled. If the linker is called and only one source file was specified on the command line, the single object file is deleted after the linking operation.
/usr/bin/cxx [ option ] ...file ... |
An option is an optional list of compile-time options.
A file is one or more file specifications separated by white space.
You cannot group multiple options after a single hyphen; that is, -pg is different than -p -g .
Supply complete relative or absolute path information when the source file is not in your current directory.
Use the -c option to stop compiler operation before linking, which results in one or more output files with the .o extension. Use the -E option to run only the preprocessor.
The detection of an error in one source file does not affect compilation of other source files specified on the same command line.
Unless you use the -x option to direct the Compaq C++ compiler to ignore file-name extensions, the compiler recognizes the following extensions as having the special significance noted:
.cxx
.CXX .cpp .CPP .cc .CC .C |
C++ source code. |
.hxx | C++ header file. |
.ixx | C++ source code already processed by the preprocessor. |
.a | Linker library. -x has no effect on files with this extension. |
.c | C source code to be compiled with the DEC C compiler. |
.i | C source code already processed by the preprocessor. |
.o | Linker object module. -x has no effect on files with this extension. |
.so | Shared object (shared library). |
Command options recognized by the cxx compiler are described in the General Options section in this chapter. Some of the options affect the behavior of the preprocessor. The preprocessor is invoked through the cxx command for C++ files, and is not invoked with a separate command. Any options not recognized by the cxx compiler are assumed to be linker options and are passed through to the linker. See the ld (1) reference page for linker options.
The following standard macro names are understood by the preprocessor. These names cannot be redefined or undefined.
__LINE__ | The current line number (a decimal integer). |
__FILE__ | The current file name (a character string). |
__DATE__ | The source file's compilation date (a character string literal of the form "Mmm dd yyyy", where the month names are the same as those generated by the asctime function, and the first character of "dd" is a space character if the value is less than 10). |
__TIME__ | The source file's compilation time (a character string literal of the form "hh:mm:ss", as in the time generated by the asctime function). |
In addition, the following macro names are predefined for Compaq C++. These names can be undefined or redefined.
__alpha
__cplusplus
__DECCXX
__DECCXX_VER
__INITIAL_POINTER_SIZE
__osf__
__unix
__unix__
These names are useful in preprocessor #ifdef and #if defined directives to isolate code intended for one of the particular cases. You can use these names anywhere you use other defined names, including within macros.
The cxx command supports the following general options:
none | Do not do any inlining. This is the default when compiling with the -O0 and -O1 optimization level. | |
manual | Inline only those function calls explicitly requested for inlining by an inline keyword. This is the default when compiling with the -O2 and -O3 flags. | |
size | Inline all of the function calls in the manual category, plus any additional calls that the compiler determines would improve run-time performance without significantly increasing the size of the program. This is the default when compiling with -O , -O4 , or -O5 . | |
speed | Inline all of the function calls in the manual category, plus any additional calls that the compiler determines would improve run-time performance, even where it may significantly increase the size of the program. | |
all | Inline every call that can be inlined while still generating correct code. Recursive routines, however, will not cause an infinite loop at compile time. |
For optimization level 0 ( -O0 ), the compiler ignores the -inline option and no inlining is done. | |||||||||||||||||||
-K | Build and use intermediate files, producing a file with the conventional extension for the type of file. These intermediate files are not removed, even when a stage encounters a fatal error. Extensions are appended to the output if it does not already have an extension. | ||||||||||||||||||
-machine_code | List the generated machine code in the listing file. To produce the listing file, you must also specify -source_listing . The default is to not list the generated machine code. | ||||||||||||||||||
-misalign |
Specify that code generated for indirect load and store instructions
should not generate alignment faults for arbitrarily aligned addresses.
Using this option increases the size of generated code and might have a
negative impact on performance.
The default condition is for code generated for indirect load instructions and store instructions to generate alignment faults for arbitrarily aligned addresses. Same as -assume noaligned_objects . |
||||||||||||||||||
-ms | Interpret source programs according to certain language rules followed by Microsoft's Visual C++. This option also defines the macro __MS . | ||||||||||||||||||
-no_misalign | Negate the -misalign option. Same as -assume aligned_objects . | ||||||||||||||||||
-no_pg | Selectively disable profiling for individual modules when using the -pg graph profiling option. | ||||||||||||||||||
-nocleanup |
Disable generation of implicit exception handlers. Procedures without
explicit handlers may have implicit handlers. For example, the compiler
creates a handler for each automatic object that has a destructor. The
compiler also creates handlers for constructors that initialize
subobjects that have destructors. In such a constructor, the compiler
creates a handler for each member with a destructor, and a handler for
each base class with a destructor. The
-nocleanup
option suppresses generation of such implicit handlers, which results
in a slightly smaller executable.
The -nocleanup option lets the compiler do additional optimizations because it is freed from concern with the abnormal transfer of control that occurs when exceptions are raised. Note that this can cause problems in your program if an exception does get raised or if setjmp() and exc_longjmp() are used. This option should not be used in programs that raise exceptions or call setjmp() and exc_longjmp() . |
||||||||||||||||||
-nodemangle | Do not pipe linker messages through the demangler. This causes linker messages to contain mangled names. By default, cxx pipes linker messages through the demangler so that demangled names are displayed. | ||||||||||||||||||
-noinline
or -no_inline |
Do not compile any function calls as inline code. | ||||||||||||||||||
-noinline_auto | Compile only inline functions that are explicitly declared to be inline. | ||||||||||||||||||
-nomember_alignment | Direct the compiler to byte-align data structure members (with the exception of bit-field members). By default, data structure members are aligned on natural boundaries (the next boundary appropriate to the type of the member) rather than the next byte. For example, an int variable member is aligned on the next longword boundary; a short variable member is aligned on the next word boundary. Using any of the #pragma member_alignment , #pragma nomember_alignment , and #pragma pack directives within the source code overrides the setting established by this option. | ||||||||||||||||||
-non_shared | Do not produce a dynamic executable file. The loader uses regular archives to resolve undefined symbols and object files ( .o suffix) from archives included in the executable produced. | ||||||||||||||||||
-noobject | Do not produce an object file. | ||||||||||||||||||
-nopragma_template | Disable all #pragma define_template directives in the source code. This option has no affect on the -define_templates command line option. | ||||||||||||||||||
-nopt | Direct the compiler not to automatically instantiate templates. | ||||||||||||||||||
-o file | Name the final output file, rather than use the default a.out . The given name is used regardless of the type of file (executable, object, assembly, or other type). | ||||||||||||||||||
-O[ n] | Set the level of optimization. Note that different optimizations are performed at each level, depending on whether you invoke the compiler with or without the -migrate option. (The -migrate option is provided for compatibility with older versions of DEC C.) The following table lists the types of optimizations that are performed if the -migrate option is not explicitly specified: | ||||||||||||||||||
|
|||||||||||||||||||
In addition to affecting the generated code, the -O level is passed on to ld and om (if om is specified). | |||||||||||||||||||
The general guidelines for optimization are as follows:
|
|||||||||||||||||||
Other switches that can possibly affect run-time size and speed are as
follows:
|
|||||||||||||||||||
When you use -g for best debugging, optimizations are suppressed. Thus, when comparing the effects of different optimization levels, you should not specify -g or -g2 . For such comparisons, you specify -g0 , which suppresses debugging information. | |||||||||||||||||||
As noted previously, different optimizations are performed at each level, depending on whether you invoke the compiler with or without the -migrate flag. The following table lists the types of optimizations that are performed if -migrate is specified: | |||||||||||||||||||
|
|||||||||||||||||||
The correspondence between optimization levels when -migrate is not specified and when it is specified is as follows: | |||||||||||||||||||
|
|||||||||||||||||||
-om | Perform code optimization after linking, including nop (No Operation) removal, .lita removal, and reallocation of common symbols. This option also positions the global pointer register so the maximum addresses fall in the global pointer-accessible window. The -om option is supported only for programs compiled with the -non_shared option. The following options can be passed directly to -om by using the -WL compiler flag: | ||||||||||||||||||
-WL,-om_compress_lita --- remove unused .lita entries after optimization, and then compress the .lita section. | |||||||||||||||||||
-WL,-om_dead_code --- remove dead code (unreachable instructions) generated after applying optimizations. The .lita section is not compressed by this option. | |||||||||||||||||||
-WL,-om_ireorg_feedback, file --- use the pixie-produced information in file.Counts and file.Addrs to reorganize the instructions to reduce cache thrashing. | |||||||||||||||||||
-WL,-om_no_inst_sched --- turn off instruction scheduling. | |||||||||||||||||||
-WL,-om_no_align_labels --- turn off alignment of labels. Normally, the -om option quadword aligns the targets of all branches to improve loop performance. | |||||||||||||||||||
-WL,-om_Gcommon, num --- set size threshold of "common" symbols. Every "common" symbol whose size is less than or equal to num will be allocated close to each other. This flag can be used to improve the probability that the symbol can be accessed directory from the global pointer register. Normally, the -om option causes the compiler to try to collect all "common" symbols together. | |||||||||||||||||||
-p | Perform profiling by periodically sampling the value of the program counter. This option affects only linking. When linking is done, this option replaces the standard run-time startup routine with the profiling run-time startup routine mcrt0.o and searches the level 1 profiling library libprof1.a . When profiling is completed, the startup routine calls the monstartup routine and produces a mon.out file that contains execution-profiling data for use with the postprocessor prof . Same as -p1 . | ||||||||||||||||||
-p0 | Do not perform profiling. This is the default. | ||||||||||||||||||
-p1 | Same as -p . | ||||||||||||||||||
-pg |
Perform call graph profiling using the
gprof
tool.
For more information on profiling C++ code, see the Tru64 UNIX Programmer's Guide and the appropriate reference pages. |
||||||||||||||||||
-pt | Direct the compiler to automatically instantiate templates. | ||||||||||||||||||
-pthread | Direct the linker to use the threadsafe version of any library specified with the -l flag when linking programs. This option also tells the linker to include the POSIX 1003.1c-conformant DECthreads interfaces in libpthread when linking the program. | ||||||||||||||||||
-ptr pathname |
Specify a repository,
with
./cxx_repository
as the default. If you specify several repositories, only the first is
writable, and the default repository is ignored unless explicitly named.
Specifying this option at link time enables Compaq C++ to recognize and use the various template instantiations within the specified repository. If you use this option, make sure that the repository current at compile time is the same one accessed by the linker at link time. |
||||||||||||||||||
-ptsuf" list" | Specify a list of file-name extensions that are valid for template definition files. | ||||||||||||||||||
-ptv | Turn on verbose or verify mode to display each phase of template instantiation as it occurs. This option is useful as a automatic instantiation learning aid. | ||||||||||||||||||
-r | Retain relocation entries in the output file. Relocation entries must be saved if the output file is to become an input file in a subsequent linker run. This option prevents final definitions from being given to common symbols; it also suppresses the diagnosis of undefined symbols. | ||||||||||||||||||
-readonly_strings | Make all string literals read only. This is the default. | ||||||||||||||||||
-rpath string | Set the rpath to the specified string. This option is meaningful for shared linkage only. | ||||||||||||||||||
-S | Compile the specified source programs and produce symbolic assembly language in corresponding files with a .s extension. Do not assemble these files. If the file name argument already has a .s extension, do nothing at all. | ||||||||||||||||||
-shared | Produce a shared object. This includes creating all of the tables for run-time linking, and resolving references to other specified shared objects. The object created may be used by the linker to make dynamic executables. | ||||||||||||||||||
-show keyword [, keyword,...] | Specify one or more items to be included in the listing file. When specifying multiple keywords, separate them by commas (with no intervening blanks). To use any of the -show keywords, you must also specify the -source_listing option. The -show keywords are as follows: |
all | Enable all options. | |
[no]expansion | Determine whether or not to place final macro expansions in the program listing. When you specify the expansion keyword, the number printed in the margin indicates the maximum depth of macro substitutions that occur on each line. | |
[no]header | Determine whether or not to produce header lines at the top of each page of listing. | |
[no]include | Determine whether or not to place contents of #include files in the program listing. | |
none | Disable all options. | |
[no]statistics | Determine whether or not to place compiler performance statistics in the program listing. | |
[no]source | Determine whether or not to place source program statements in the program listing. |
The default is to show page headers and source; that is:
-show header,source . |
|||||||||
-signed | Cause all char declarations to have the same machine representation and value set as signed char declarations. This is the default. | ||||||||
-source_listing | Produce a source code listing file of the same name as the source file, but with the extension .lis . | ||||||||
-strong_volatile |
Allow byte and word access of data at byte granularity by using a
load-locked instruction sequence for byte and word stores. This means
that, for assignments to objects that are less than or equal to 16 bits
in size and have been declared as volatile, assignments to adjacent
volative small objects by different threads in a multithreaded program
will not cause one of the objects to receive an incorrect value.
The generated code includes a load-locked instruction for the enclosing longword or quadword, an insertion of the new value of the object, and a store-conditional instruction for the enclosing longword or quadword. |
||||||||
-t |
Select a name to use for a particular pass, startup routine, or
standard library, from the set of
-t [fablyzrnL]
,
-h
path
, and
-B
string
flags. These arguments are processed from left to right so
their order is significant. When the compiler encounters the
-B
flag, the selection of names takes place using the last
-h
and
-t
flags. Therefore, the
-B
flag is always required when using
-h
or
-t
. Sets of these flags can be used to select any combination of names.
The -p[01] flags must precede all -B flags because they can affect the location of run times and what run times are used. Use the -t [fablyzrnL] suboptions to select the names. The names selected are those designated by the characters following the -t flag as follows: f gemc_cxx |
||||||||
-taso |
Tell the linker that the executable file should be loaded in the lower
31-bit addressable virtual address range. You can also use the
-T
and
-D
options to the
ld
command to ensure that the adresses of text and data segments are
loaded into low memory.
Besides setting default addresses for text and data segments, the -taso option also causes shared libraries linked outside the 31-bit address space to be appropriately relocated by the loader. If you specify -taso and also specify text and data segment addresses with -T and -D , those addresses override the -taso default addresses. The -taso option is useful for porting 32-bit programs to Tru64 UNIX systems. |
||||||||
-threads | Direct the linker to use the thread-safe version of any library specified with the -l flag when linking programs. This option also tells the linker to include both the DECthread interfaces that are conformant with POSIX 1003.4a Draft 4. The flag is supported only for compatability with earlier releases of the Tru64 UNIX operating system. New designs should use the -pthread option. | ||||||||
-tune option |
Select processor-specific instruction tuning for implementations of the
operating system architecture. Using
-tune
causes the generated code to run correctly on all implementations of
the architecture. Tuning for a specific implementation may improve
run-time performance; however, code tuned for a specific target may run
slower on another target.
The following options are supported:
|
||||||||
-unroll n | Control loop unrolling done by the optimizer. The integer n signifies the number of times to unroll loop bodies. Specifying 0 for n tells the optimizer to use its own default unroll amount. This is the default. | ||||||||
-unsigned | Cause all char declarations to have the same machine representation and value set as unsigned char declarations. The -unsigned option overrides -signed if both are specified on the command line. | ||||||||
-use_ld_input |
Direct the Compaq C++ compiler to record in the writable repository
the names of requested automatic template instantiation object files in
a linker options file.
The Compaq C++ compiler then adds the linker options file to the ld command line using the ld -input <file> option. The default behavior is to add the instantiation file names directly to the ld command line. You can use the -use_ld_input option to reduce long ld command lines that cause ld to fail because of Arg list too long errors. This option is supported only on Tru64 UNIX Version 3.2C and later systems. |
||||||||
-v | Print the names of compiler phases as they execute, along with their arguments and input and output files. This option also prints resource usage in the following format: user time, system time, total elapsed time, percentage use of CPU cycles. | ||||||||
-V | Enable printing of the version of the compiler and its phases. | ||||||||
-varargs | Print warnings for all lines that may require macros contained in the header file varargs.h . | ||||||||
-verbose | Include identifiers with messages the compiler issues in response to #pragma message directives. | ||||||||
-volatile | Compile all variables as volatile . | ||||||||
-vptr_size | Make 64 bits the default size of virtual function and virtual base pointers in a C++ class object (64 bits is the normal default). This option also enables #pragma pointer_size and passes -taso to the linker. | ||||||||
-vptr_size_short | Make 32 bits the default size of virtual function and virtual base pointers in a C++ class object. This option also enables #pragma pointer_size and passes -taso to the linker. | ||||||||
-w | Suppress warning and informational compiler messages, but not back-end messages. Same as -w2 . | ||||||||
-w0 | Display all levels of compiler messages. | ||||||||
-w1 | Suppress informational compiler messages. This is the default. | ||||||||
-w2 | Same as -w . | ||||||||
-W
c[
c...],
arg1[, arg2...] |
Pass the arguments arg2...] to the compiler stages c[ c...]. Use this option to pass arguments through to a particular stage, which otherwise would be consumed by an earlier stage. The c argument selects the compiler stage in the same way as it does in the -H option. Valid characters for c are: a, b, f, l, L, n, r, t, y , and z . | ||||||||
-weak_volatile | Do not generate load-locked instructions for a sequence of byte or word stores for assignments to objects that are less than or equal to 16 bits in size and have been declared as volatile. This allows byte or word access to memory-like I/O devices for which larger access will not cause read or write side effects. Because the sequence does not access byte or word data independently directly in memory (that is, ensure byte granularity), adjacent volatile data can be corrupted when such byte or word accesses are performed in a multithreaded environment (for example, two volative short s stored in a longword and accessed asynchronously). | ||||||||
-writable_strings | Make string literals writeable. | ||||||||
-x cxx | Cause all subsequent file names to be compiled as C++ source files, regardless of their suffixes (except .a and .o). This option applies to all following file names up to the next -x option on the command line. | ||||||||
-x none |
Cause all subsequent file names to be treated according to their file
name suffixes. This option reverses the effect of the
-x cxx
option. It applies to all following file names until the next
-x
option on the command line.
In the following example, files one.cxx and two.c will be compiled
as C++ source files, and file three.c will be compiled as a C source
file:
|
||||||||
-xref
-xref_stdout |
Direct the Compaq C++ compiler to generate a data file that the DEC
FUSE Database Manager uses to create a cross-reference database file.
This database file is used by the DEC FUSE C++ Class Browser, Call
Graph Browser, and Cross-Referencer.
Specifying the -xref_stdout option directs the compiler to output the data file to standard output. |
||||||||
-xtaso | Set the default pointer size of the compilation unit to 64 bits (for all pointers except virtual function and virtual base pointers; 64 bits is the normal default). This option enables #pragma pointer_size and passes -taso to the linker. | ||||||||
-xtaso_short | Set the default pointer size of the compilation unit to 32 bits (for all pointers except virtual function and virtual base pointers). This option also enables #pragma pointer_size and passes -taso to the linker. The this pointer is unaffected by this option, it remains the system default pointer size, which is 64 bits. | ||||||||
-Zp n | Align structure members on alignment specified by the integer n, where n can be 1, 2, or 4. This option specifies packing so that each structure member after the first is stored on n-byte boundaries as specified by the flag you choose. When you specify the -Zp option without an n value, structure members are packed on 1-byte boundaries. |
The following cxx command options control the action of the preprocessing phase:
-cpp | Run the preprocessor on the source files before compiling. This is the default. If both -cpp and -nocpp are included on the command line, the option specified last is in effect. |
-nocpp | Do not run the preprocessor on the source files before compiling. If both -nocpp and -cpp are included on the command line, the option specified last is in effect. If -P or -E is specified, -nocpp has no effect. |
-C | Prohibit the preprocessor from removing comments in the source file. (Use with the -E or -Em option.) |
-D
name=def
-D name |
Define name to the preprocessor, as if the line #define name def were prepended to the C++ source file. There can be a space between the option and name. If name or def contains a dollar sign ($), they must be surrounded by apostrophes ('). If no =def is specified, the name is defined as 1. |
-E | Run only the preprocessor on the source files (regardless of whether a suffix exists), and send the result to the standard output. This sets the -cpp option. |
-Em | Run only the preprocessor on the source files (regardless of whether a suffix exists), and produce makefile dependencies instead of the usual output. For each source file, the preprocessor creates one makefile entry naming the object file and listing all included files as dependencies. Same as -M . |
-I | Do not search for #include files in the standard directories, /usr/include/cxx and /usr/include . Because -I can be followed by a directory, do not place a nondirectory file name on the command line immediately following -I . If -I is being used without a directory, follow it with another option or place it at the end of the command line to avoid misinterpretation. |
-I dir |
Define the directory name
dir to the preprocessor for use in searching for quoted and
angle-bracketed include files. There can be a space between the option
and
dir. The preprocessor searches for include file names that do
not begin with a slash (/) in the following order:
If -nocurrent_include is specified, the preprocessor does not search in the directory containing the source file. |
-M | Run only the preprocessor on the source files (regardless of whether a suffix exists), and produce makefile dependencies instead of the usual output. For each source file, the preprocessor creates one makefile entry naming the object file and listing all included files as dependencies. Same as -Em . |
-MD | Produce a dependency file, which has the suffix .d appended to the object file name. This dependency file is created even if the object file is not. The information and the format in the dependency file is identical to that produced by the -M flag. The -MD flag allows dependency information to be generated at the same time that a compilation is occurring. |
-nocurrent_include | Do not search for quoted include files in the directory containing the source file with the #include line. The preprocessor will still search the directories specified by the -I option and in the standard directory /usr/include . See also the -I dir option. |
-oldcomment | Remove comments from preprocessor output files and replace those comments with nothing. |
-P | Run only the preprocessor and put the result for each source file in a corresponding .ixx file, without including line numbers. The -P option has no effect if specified after -E or -Em . If specified before -E , it overrides -E . If specified before -Em , it writes the makefile dependencies to .ixx files. |
-U name | Cancel any command-line definition of name to the preprocessor, as if the line #undef name were prepended to the C++ source file. There can be a space between the option and name. If name contains a dollar sign ($), name must be surrounded by apostrophes ('). The undefine operation occurs after any definitions produced by the -D options. Symbols defined by default are listed in the Description section. |
If the environment variable COMP_HOST_ROOT is set, the value is used as the root directory for all stage names rather than the default slash (/). If the environment variable COMP_TARGET_ROOT is set, the value is used as the root directory for all include and library names rather than the default slash (/). COMP_TARGET_ROOT affects the standard directory for include files, /usr/include , and the standard library, /usr/lib/libc.a . If COMP_TARGET_ROOT is set, COMP_TARGET_ROOT/usr/lib is the only directory that is searched for libraries using the -l x option.
If the environment variable TMPDIR is set, the value is used as the directory to hold any temporary files rather than the default /tmp directory.
If the environment variable RLS_ID_OBJECT is set and a link occurs, the value is used as the name of an object to link. The RLS_ID_OBJECT environment variable is always the last object specified to the linker.
% cxx -g -DUSE_CONCENTRATOR -o netmud netmud.cxx |
This example creates an executable file named netmud with symbol table information for full symbolic debugging ( -g ). The -D option defines the macro name USE_CONCENTRATOR for the preprocessor.
% cxx -o gfview -I/usr/kafka/src:/usr/barnes/include gfview.cxx |
This command line creates an executable file from the gfview.cxx source file. The -o option names the output file gfview . The -I option directs the preprocessing phase to search the specified directories for include files not found in the current working directory.
% cxx -c io_module.cxx |
This example preprocesses and compiles the source file io_module.cxx and produces an object file named io_module.o . Processing stops after creating the object file.
% cxx -o newsreader io_module.o ui.cxx -L/users/dave -lnews |
This example creates an executable file and the -o option names the file newsreader . The source file ui.cxx is preprocessed and compiled and then linked with the object file io_module.o . The link operation uses the library specified by -l (libnews.a) . The linker first looks for the library in the current working directory, then in the directory specified by -L (/users/dave) , and finally in $PATH .
% cxx -pg a.cxx b.cxx -no_pg c.cxx |
This command line enables gprof profiling for files a.cxx and b.cxx and disables profiling for file c.cxx .
% cxx one.cxx -x cxx two.c -x none three.c |
This example causes files one.cxx and two.c to be compiled as C++ source files, and file three.c to be compiled as a C source file.
The cxx compiler generates diagnostic and error messages. The line number and file name where the source code that triggered the message resides are printed along with the diagnostic.
filename.cxx | C++ source code input file |
filename.o | Object file |
a.out | Default output file |
/usr/include
/usr/include/cxx |
Standard directories for include files |
Compaq C++ 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 Compaq C++ program is not linked properly, some static objects will not be initialized at program startup.
If you choose to use the
ld
linker directly, you may need to modify your
ld
command whenever you install a new version of the Compaq C++ compiler
or the Tru64 UNIX operating system. After doing such an installation,
you should invoke the
cxx
command and specify the
-v
option to display the
ld
command in use. Then, compare this
ld
command with your
ld
command and make any necessary changes. See Section 1.1, and 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.
It is often difficult to decipher mangled names that may 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, Compaq C++ 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 Compaq C++, 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 Compaq 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 Compaq C++ Class Library Reference Manual for a detailed explanation of the class library packages supplied with Compaq C++.
Linking to the Compaq C++ Class Library
Most of the Compaq 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 |
These and other Compaq C++ Class Library packages are documented in
the Compaq C++ Class Library Reference Manual.
1.5 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 8.
Previous | Next | Contents | Index |