Linking the C Library [ HP C/iX Reference Manual ] MPE/iX 5.0 Documentation
HP C/iX Reference Manual
Linking the C Library
This section describes the procedure necessary to link C library
functions into your program using the MPE/iX LINK command. For many
applications, linking the LIBCINIT.LIB.SYS file in the RL list, as done
by the CCXLLK and CCXLGO commands, is sufficient. Applications that use
mathematical or random number functions, or programs compiled using ANSI
mode, will nee to link with additional libraries.
C Library Organization
The C library consists of several files that may be separated into two
functional areas: the standard library and the mathematical library.
The standard library consists of the input/output functions, the general
utility functions that perform operations such as string and memory
manipulation, and the program startup functions. All C programs must
link in the standard library because it contains the startup routines
necessary for program execution. Failure to link in this library will
result in a linker or loader error. The standard library is available in
the system executable library (XL.PUB.SYS) and also as a relocatable
library (RL).
The math library consists of additional mathematical functions, such as
the trigonometric and logarithmic functions, that perform floating point
operations. The math library is only available in RL form.
For further information on the organization of the HP C/iX Library, refer
to the HP C/iX Library Reference Manual.
Linking the Library Files
To use the executable standard library, add the LIBCINIT.LIB.SYS file to
the RL list when linking your program. To use the relocatable standard
library, add the LIBC.LIB.SYS file to the RL list when linking. Note
that you may choose either the executable (XL) or relocatable (RL)
library form, but not both.
Additionally, if the program is compiled using ANSI mode (the -Aa
option), the relocatable library LIBCANSI.LIB.SYS must also be added to
the RL list regardless of whether LIBCINIT.LIB.SYS or LIBC.LIB.SYS is
used. This is to ensure that certain file behaviors conform to ANSI
specifications. For a detailed description of LIBCANSI.LIB.SYS, see the
HP C/iX Library Reference Manual. For a detailed discussion of the LINK
command, see the MPE/iX Commands Reference Manual.
To use the math library, add the LIBM.LIB.SYS file to the RL list when
linking your program. The LIBM.LIB.SYS file must precede the
LIBC.LIB.SYS file in the RL list if the RL form of the standard library
is used. The ordering of the files is significant because of the
interdependencies of the libraries. The ordering is not significant if
the XL form of the standard library is linked.
In addition to LIBM.LIB.SYS, there is also LIBMANSI.LIB.SYS, the ANSI
conforming version of the math library. You must decide which version of
the math library to use and link with the appropriate RL.
The rand and srand functions are conceptually part of the standard
library but reside in a different library file, LIBCRAND.LIB.SYS. To use
these functions, add the LIBCRAND.LIB.SYS file to the RL list when
linking your program. These functions are not available in XL form.
This special treatment for the rand and srand functions is due to a name
conflict between the HP C/iX library function rand and the MPE/iX
compiler library function rand.
Examples.
To link the object file MYOBJ and the RL form of the standard library
into the program file MYPROG, enter:
LINK FROM=MYOBJ; TO=MYPROG; RL=LIBC.LIB.SYS
To link the object file MYOBJ together with the random number generation
functions rand and srand, the math library routines, and the RL form of
the standard library, enter:
LINK FROM=MYOBJ; TO=MYPROG; RL=LIBCRAND.LIB.SYS,LIBM.LIB.SYS,LIBC.LIB.SYS
Remember that either LIBC.LIB.SYS or LIBCINIT.LIB.SYS must be linked into
your program.
To link a program under ANSI mode, enter:
LINK FROM=OBJFILE; TO=PROGFILE; RL=LIBCINIT.LIB.SYS,LIBCANSI.LIB.SYS
Non-ANSI is the default mode.
MPE/iX 5.0 Documentation