Sun Studio 12: C++ User's Guide

A.2.55 –mt

Compile and link for multithreaded code.

This option passes -D_REENTRANT to the preprocessor and passes -lthread in the correct order to ld.

The -mt option is required if the application or libraries are multithreaded.

To ensure proper library linking order, you must use this option, rather than -lthread, to link with libthread.

If you are using POSIX threads, you must link with the options -mt -lpthread. The -mt option is necessary because libC (compatibility mode) and libCrun (standard mode) need libthread for a multithreaded application.

Modules that are compiled with -mt must also be linked with -mt. For a complete list of compiler options that must be specified at both compile time and at link time, see 3.3.3 Compile-Time and Link-Time Options.

If you compile one translation unit with -mt, compile all units of the program with -mt.

If you are mixing parallel Fortran objects with C++ objects, the link line must specify the -mt option.

A.2.55.1 Warnings

To ensure proper library linking order, you must use this option, rather than -lthread, to link with libthread.

If you are using POSIX threads, you must link with the -mt and -lpthread options. The -mt option is necessary because libCrun (standard mode) and libC (compatibility mode) need libthread for a multithreaded application.

If you compile and link in separate steps and you compile with -mt, be sure to link with -mt, as shown in the following example, or you might get unexpected results.


example% CC -c -mt myprog.cc
example% CC -mt myprog.o

If you are mixing parallel Fortran objects with C++ objects, the link line must specify the -mt option.

C99 support is not available in compat mode (-compat=4).

See also

–xnolib, 10.5 Cache Member Variables, Multithreaded Programming Guide, Linker and Libraries Guide