Share via


Compiling and Linking Multithread Programs

OverviewHow Do ISample

To compile and link the multithread program BOUNCE.C from within the development environment

  1. Click New on the File menu, then click the Projects tab.

  2. On the Projects tab, click Console Application, and name the project.

  3. Add the file containing the C source code to the project.

  4. On the Project menu, click Settings. In the Project Settings dialog box, click the C/C++ tab. Select Code Generation from the Category drop-down list box. From the Use Run-Time Library drop-down box, select Multithreaded. Click OK.

  5. Build the project by clicking the Build command on the Build menu.

To compile and link the multithread program BOUNCE.C from the command line

  1. Ensure that the Win32 library files and LIBCMT.LIB are in the directory specified in your LIB environment variable.

  2. Compile and link the program with the CL command-line option /MT:

    CL /MT BOUNCE.C
    
  3. If you choose not to use the /MT option, you must take these steps:

    • Define the _MT symbol before including header files. You can do this by specifying /D _MT on the command line.

    • Specify the multithread library and suppress default library selection.

    The multithread include files are used when you define the symbolic constant _MT. You can do this with the CL command line option /D _MT or within the C source file before any include statements, as follows:

    #define _MT
    #include <stdlib.h>