Sun Studio 12 Update 1: C User's Guide

B.2.50 -mt

Use this option to compile and link multithreaded code using the Solaris threads or POSIX threads API. The -mt option assures that libraries are linked in the appropriate order.

This option passes -D_REENTRANT to the preprocessor.

To use Solaris threads, include the thread.h header file and compile with the —mt option. To use POSIX threads on Solaris platforms, include the pthread.h header file and compile with the —mt —lpthread options.

On Linux platforms, only the POSIX threads API is available. (There is no libthread on Linux platforms.) Consequently, —mt on Linux platforms adds —lpthread instead of —lthread. To use POSIX threads on Linux platforms, compile with —mt.

Note that when compiling with —G, neither —lthread nor —lpthread are automatically included by —mt. You will need to explicitly list these libraries when building a shared library.

The —xopenmp option (for using the OpenMP shared-memory parallelization API) includes —mt automatically.

If you compile with -mt and link in a separate step, you must use the -mt option in the link step as well as the compile step. If you compile and link one translation unit with -mt, you must compile and link all units of the program with -mt

B.2.50.1 See Also

–xnolib, and the Solaris Multithreaded Programming Guide, and Linker and Libraries Guide