C/C++ Libraries

This chapter describes the following:

The Watcom C/C++ library routines are described in the Watcom C Library Reference, and the Watcom C++ Class Library Reference.

C/C++ library directory structure

The Watcom C/C++ libraries are located under the /usr/lib directory.

fig: ./images/dir.gif

C libraries

Due to the many code generation strategies possible in the 80x86 family of processors, a number of versions of the libraries are provided. You must use the libraries that coincide with the particular code generation strategy or model that you've selected. For the type of code generation strategy or model that you intend to use, refer to the description of the m{f,s,m,c,l,h} memory model compiler option. The various code models supported by Watcom C/C++ are described in the chapters 16-bit Memory Models (in the 16-bit Topics supplement), and 32-bit Memory Models (in this manual).

We've selected a simple naming convention for the libraries that are provided with Watcom C/C++. Letters are affixed to the file name to indicate the particular strategy with which the modules in the library have been compiled.

The following letters apply only to 16-bit libraries, and indicate the memory model used:

Letter Memory Model Library
s small (small code, small data) clibs.lib
m medium (big code, small data) clibm.lib
c compact (small code, big data) clibc.lib
l large (big code, big data) clibl.lib
h huge (big code, huge data) clibh.lib

The following letters apply to 32-bit libraries (for the flat and small memory models), and indicate the compiler option used:

Letter Option Library
3r 3r, 4r or 5r clib3r.lib
3s 3s, 4s or 5s clib3s.lib

C 16-bit shared library

A portion of the 16-bit Watcom C Library is also stored in a memory-resident library called the system shared library. On multi-tasking systems, it makes sense that commonly-used library routines such as read() and write() be shared among processes. By sharing the same code, the memory requirement for applications is reduced. The functions in the shared library are independent of the memory model, so they can be used by any small/large code, small/large/huge data applications.

C++ class libraries

The Watcom C++ class library routines are described in the Watcom C++ Class Library Reference.

The Watcom C++ 16-bit Class Libraries for various combinations of compiler options and memory models are listed below:

Classes Option Model Library
iostream, string small plibs.lib
medium plibm.lib
compact plibc.lib
large plibl.lib
huge plibh.lib
Complex fpc small cplxs.lib
medium cplxm.lib
compact cplxc.lib
large cplxl.lib
huge cplxh.lib
Complex fpi or fpi87, 7 small cplx7s.lib
medium cplx7m.lib
compact cplx7c.lib
large cplx7l.lib
huge cplx7h.lib

These libraries are independent of the operating system. The ``7'' designates a library compiled with the 7 option.

The Watcom C++32-bit Class Libraries for various compiler options for the small and flat memory models are listed below.

Classes Compiler Option Library
iostream, string 3r, 4r or 5r plib3r.lib
3s, 4s or 5s plib3s.lib
Complex fpc, 3r, 4r or 5r cplx3r.lib
fpc, 3s, 4s or 5s cplx3s.lib
Complex 7, fpi or fpi87, and 3r, 4r or 5r cplx73r.lib
7, fpi or fpi87, and 3s, 4s or 5s cplx73s.lib

These libraries are independent of the operating system. The ``3r'' and ``3s'' suffixes refer to the argument-passing convention used. The ``7'' designates a library compiled with the 7 option.

C/C++ math libraries

In general, a Math library is required when floating-point computations are included in the application. The Math libraries are operating-system independent. The Math libraries are placed under the /usr/lib directory.

The following situations indicate that one of the Math libraries should be included when linking the application.

  1. If an application uses one or more of the functions described in the math.h header file, then a Math library must be included.
  2. If an application is linked and the message:
        _fltused_ is an undefined reference
        
    

    appears, then a Math library must be included.

  3. (16-bit only) If an application is linked and the message:
        __init_87_emulator is an undefined reference
        
    

    appears, then one of the modules in the application was compiled with one of the fpi, fpi87, fp2, fp3 or fp5 options.

    If the fpi option was used, the 80x87 emulator library (emu87.lib) or the 80x87 fixup library (noemu87.lib) should be included when linking the application.

    If the fpi87 option was used, the 80x87 fixup library noemu87.lib should be included when linking the application.

  4. (32-bit only) If an application is linked and the message:
        __init_387_emulator is an undefined reference
        
    

    appears, then one of the modules in the application was compiled with one of the fpi, fpi87, fp2, fp3 or fp5 options.

    If the fpi option was used, the 80x87 emulator library (emu387.lib) should be included when linking the application.

    If the fpi87 option was used, the empty 80x87 emulator library noemu387.lib should be included when linking the application.

Normally, the compiler and linker will automatically take care of this. Simply ensure that the WATCOM environment variable includes the location of the Watcom C/C++ libraries.

C/C++ 80x87 math libraries

One of the following Math libraries must be used if any of the modules of your application has been compiled with one of the Watcom C/C++ compiler fpi, fpi87, fp2, fp3 or fp5 options, and your application requires floating-point support for the reasons given above.

The 16-bit libraries are as follows:

Library Memory Model
math87s.lib small
math87m.lib medium
math87c.lib compact
math87l.lib large
math87h.lib huge
noemu87.lib any
emu87.lib any

The 32-bit libraries for the small and flat memory models are as follows:

Library Compiler Option
math387r.lib 3r, 4r or 5r
math387s.lib 3s, 4s or 5s
emu387.lib

The fpi compiler option causes an 80x87 numeric data processor emulator to be linked into your application, in addition to any 80x87 math routines that were referenced. For QNX, there is a common 80x87 emulator task that's used so that there's only one copy of the emulator in memory at any one time. This emulator decodes and emulates 80x87 instructions when an 80x87 isn't present in the system.

When the fpi87 compiler option is used exclusively, the emulator isn't included. In this case, the application must be run on personal computer systems equipped with the numeric data processor.

C/C++ alternate math libraries

One of the following Math libraries must be used if any of the modules of your application has been compiled with the fpc option of the Watcom C/C++ compiler, and your application requires floating-point support for the reasons given above. The following Math libraries include support for floating-point, which is done out-of-line through runtime calls.

The 16-bit libraries are as follows:

Library Memory Model
maths.lib small model
mathm.lib medium model
mathc.lib compact model
mathl.lib large model
mathh.lib huge model

The 32-bit libraries are as follows:

Library Compiler Option
math3r.lib 3r, 4r or 5r
math3s.lib 3s, 4s or 5s

Applications that are linked with one of these libraries don't require a numeric data processor for floating-point operations. If one's present in the system, it's used; otherwise floating-point operations are simulated in software.

Runtime initialization routines

Source files are included in the package for the Watcom C/C++ application startup (or initialization) sequence.

16-bit only

For QNX, these files are located in the directory /usr/lib/src/startup.

The following is a summary list of the startup files for QNX:

cmain.c
final part of initialization sequence
mdef.inc
macros included by cstart.asm
models.inc
included by cstart_*.asm
start.asm
included by cstart_*.asm
start_c.asm
startup for compact memory model
start_h.asm
startup for huge memory model
start_l.asm
startup for large memory model
start_m.asm
startup for medium memory model
start_s.asm
startup for small memory model

The assembler file cstart.asm contains the first part of the initialization code, and the remainder is continued in the file cmain.c. The assembler files, cstart_*.asm, define the type of memory model, and include cstart.asm. It's cmain.c that calls your mainline routine, main().

32-bit only

For QNX, these files are located in the directory /usr/lib/src/startup.

The following is a summary list of the startup files for QNX:

cstrt386.asm
startup for small memory model
mdef.inc
macros included by cstrt386.asm
cmain.c
final part of initialization sequence

The assembler file cstrt386.asm contains the first part of the initialization code, and the remainder is continued in the file cmain.c. It's cmain.c that calls your mainline routine main().

The source code is provided for those who wish to customize the initialization sequence for special applications.