# Compiling and Linking Multithreaded Programs

When building a multithreaded application, be sure to link against the thread-safe version of the Fortran run-time libraries and to enable thread safety. This is specified by the threads and reentrancy:threaded compiler options.The Visual Studio* integrated development environment (IDE), described later in this topic, can also be used on Windows*.

You must also link with the correct library files. Some libraries, such as those for OpenMP* or coarrays, are always linked dynamically.

## Linux* and macOS

To create statically-linked, multithreaded programs, link with the static library named libifcoremt.a.

To use shared libraries, link your application with libifcoremt.so (Linux*) or libifcoremt.dylib (macOS).

To compile and link your multithreaded program from the command line:

1. Make sure the IA32ROOT environment variable points to the directory containing your library files.

2. Compile and link the program with the -threads option. For example:

       ifort -threads mythread.f90

   ### Note

   To ensure that a threadsafe and/or reentrant run-time library is linked and correctly initialized, option threads should also be used for the link step and for the compilation of the main routine.

## Windows*

To create statically linked multithreaded programs, link with the re-entrant support library LIBIFCOREMT.LIB.

To use shared libraries, use the shared LIBIFCOREMD.DLL library, which is also re-entrant, and is referenced by linking your application with the LIBIFCOREMD.LIB import library.

Programs built with LIBIFCOREMT.LIB do not share Fortran run-time library code or data with any dynamic-link libraries they call. You must link with LIBIFCOREMD.LIB if you plan to call a DLL.

Additional Notes:

- The /threads option is automatically set when a multithreaded application is specified in the IDE.

- Specify the compiler options /libs=dll and /threads if you are using both multithreaded code and DLLs.

- You can use the /libs=dll and /threads options only with Fortran Console projects, not QuickWin applications.

To compile and link your multithreaded program using Visual Studio*

1. Create a new project by clicking File > New > Project.

2. Select the Intel® Visual Fortran project type from Intel® Visual Fortran Projects in the left pane.

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

   From the Project menu, select Properties. The Property Pages dialog box appears.

4. Choose the Fortran folder, Libraries category, and set the Runtime Library to Multithreaded or Multithread DLL (or their debug equivalents).

5. Create the executable file by choosing Build Solution from the Build menu.

To compile and link your multithreaded program from the command line:

1. Make sure your LIB environment variable points to the directory containing your library files.

2. Compile and link the program with the /threads option. For example:

       ifort /threads mythread.f90

   ### Note

   To ensure that a threadsafe and/or reentrant run-time library is linked and correctly initialized, option threads should also be used for the link step and for the compilation of the main routine.

Parent topic: Compilation