|
|
HP C++ Programmer's Guide: HP 9000 Series Workstations and Servers > Chapter 3 Compiling and Executing HP C++ ProgramsSystem Library and Header Files |
|
This section discusses the two types of libraries provided with HP C++:
There are several libraries providing system services that are included with HP-UX. You can access HP-UX standard libraries by using header files that declare interfaces to those libraries. These library routines are documented in the HP-UX Reference Manual. The standard HP-UX header files are located in /usr/include. To use a system library function, your HP C++ source code must include the preprocessor directive #include. For example,
where filename.h is the name of the C++ header file for the library function you want to use. By enclosing filename.h in angle brackets, the HP C++ preprocessor looks for that particular header file in a standard location on the system. The HP C++ preprocessor first looks for header files in /usr/include/CC (in /opt/CC/include for HP-UX 10.x C++ versions); if any are not found, it then searches /usr/include. You can use -Idir options to modify the search path. If the -Idir option is specified, the HP C++ preprocessor first looks for #include files in the directories specified in dir before looking into the standard include directories. If you want to use the getenv function that is in the standard library files /lib/libc.sl and /lib/libc.a (or /usr/lib/libc.sl and /usr/lib/libc.a for HP-UX 10.x C++ versions), you should specify
because the external declaration of getenv is found in the header file /usr/include/stdlib.h. In addition to standard HP-UX system libraries, HP C++ provides the following C++ run-time libraries: The stream library includes class libraries for buffering and formatting I/O operations. It consists of several main I/O classes providing the fundamental facility for I/O conversion and buffering. The stream library also provides classes derived from main classes offering extended I/O functionality such as in-memory formatting and file I/O. For more detailed documentation of this library, refer to the C++ Language System Library Manual. The Ostream library is no longer provided with HP C++. It was provided with version 2.1 for backward compatibility with the AT&T C++ version 1.2 stream I/O library. The newer C++ stream library (available since version 2.0) is mostly upward compatible with the older stream library, but there are a few places where differences may affect programs. These differences are discussed in chapter 3 of the C++ Language System Library Manual, under "Converting from Streams to Iostreams." The task library is a multiple threaded, co-routine class library that enables users to simulate, control, and model UNIX system processes in an object-oriented paradigm. This library also encapsulates reusable tasking primitives such as the scheduler, task queue, timer, and interrupt handler. The task library is useful for simulations or pseudo parallel-processing algorithms. For more detailed documentation of this library, refer to the C++ Language System Library Manual. The complex library implements the data type of complex numbers as a class complex. It overloads the standard input, output, arithmetic, assignment, and comparison operations. It also defines the standard exponential, logarithm, power, and square-root functions, as well as the trigonometric functions of sine, cosine, hyperbolic sine, and hyperbolic cosine. For more detailed documentation of this library, refer to the C++ Language System Library Manual. The HP Codelibs library contains many general-purpose classes you can use in your applications, including:
The header files for the HP Codelibs library are in the directory /usr/include/codelibs (/opt/CC/include/codelibs for HP-UX 10.x C++ versions). Use -I/usr/include/codelibs to direct the compiler to search these header files. For more information about this library, refer to the Codelibs Library Reference - Version 2.100. The USL C++ Standard Components library contains many general-purpose classes you can use in your applications, including:
The header files for the Standard Components library are in the directory /usr/include/SC (/opt/CC/include/SC for HP-UX 10.x C++ versions). Use -I/usr/include/SC to direct the compiler to search these header files. A collection of program development tools for use with the Standard Components library are in /usr/bin. These include hier, incl, publik, dem, and g2++comp. For more information about the Standard Components, refer to the USL C++ Standard Components Manual. To see the online manual pages, first add the directory /usr/CC/man/SC (/opt/CC/share/man for HP-UX 10.x C++ versions) to your MANPATH environment variable. Then type man name where name is a particular manual page. For an introduction to Standard Components, type man SC_intro and man SC_tools_intro. Table 3-2 “HP C++ Library Files” lists the files containing the HP C++ run-time libraries. Different libraries are used depending on whether or not you use exception handling. Table 3-2 HP C++ Library Files
For HP-UX 10.x C++ versions, the HP C++ run-time environment supports multi-threaded applications. The following HP C++ libraries are thread-safe:
There are no interface changes to the functions in these libraries nor in the standard include files in /usr/include and /opt/CC/include/CC. However, there are new reentrant versions of the functions chr_r, str_r, form_r, hex_r, dec_r, and oct_r. In order to link with these functions, you must include the stream.h header file in your source file and add the -D_THREAD_SAFE compile time flag to your compilation line. Also, in order to pick the thread safe version of the I/O routines, cout, cin, and cerr, you must include iostream.h in your source files and add the -D_THREAD_SAFE compile time flag to your compilation line. To guarantee that your I/O results from one thread are not intermingled with I/O results from other threads, you should protect your I/O statement with locks. For example:
There are no new compiler options for compiling multi-threaded programs. HP C++ includes the following header files for interface to C++ run-time libraries: For more detailed documentation on these headers, refer to C++ Language System Library Manual. For information on the header files for the HP Codelibs library, refer to the Codelibs Library Reference - Version 2.100. For information on the header files for the Standard Components library, refer to the USL C++ Standard Components Manual. The above header files are located in the directory /usr/include/CC. The header files for the HP Codelibs library are in the directory /usr/include/codelibs. (In /opt/CC/include/codelibs for HP-UX 10.x C++ versions.) Use -I/usr/include/codelibs to direct the compiler to search these header files. The header files for the Standard Components library are in the directory /usr/include/SC. (In /opt/CC/include/SC for HP-UX 10.x C++ versions.) Use -I/usr/include/SC to direct the compiler to search these header files. You can compile and link any C++ modules to one or more libraries. HP C++ automatically links /usr/lib/libC.sl (the HP C++ run-time library, including the stream library) and /lib/libc.sl (the HP-UX system library) with a C++ program. The ANSI C versions of the C++ run-time library are also included, libC.ansi.sl and libC.ansi.a. If you have compiled with the +a1 option, you must also pass +a1 to the CC command when linking to make sure the linker uses these libraries. If you want archive libraries instead of shared libraries, use the -a,archive linker option. (See the section "Linking Archive or Shared Libraries" later in this chapter for more information.) You can specify other libraries using the -l option. For example, in order to use the complex library, you must specify -lcomplex:
Your C++ run-time library may require that additional HP-UX standard libraries be specified. For example, the complex library uses the HP-UX math library for mathematical functions. So, for example, you might need to specify -lm for the math library:
|
|