| > The Program Execution Monitor > Compilation |

### The Program Execution Monitor compilation

In comparison with many other boost libraries, which are completely implemented in header files, compilation and linking with the Program Execution Monitor may require additional steps. The Program Execution Monitor presents you with options to either built and link with a standalone library or include the implementation directly into your program. If you opt to use the library the Program Execution Monitor header implements the auto-linking support and following flags can be used to configure compilation of the Program Execution Monitor library and your program:

Table 2. Program Execution Monitor compilation flags

Variable | Usage
--- | ---
BOOST_TEST_DYN_LINK | Define this flag to build/use dynamic library.
BOOST_TEST_NO_LIB | Define this flag to prevent auto-linking.

#### Standalone library compilation

If you opted to link your program with the standalone library, you need to build it first. To build a standalone library all C++ files (.cpp), that constitute Program Execution Monitor implementation need to be listed as source files in your makefile[1].

The makefile for use with Boost.Build system is supplied in `libs/test/build` directory. The Program Execution Monitor can be built as either static or dynamic library.

##### Static library compilation

There are no additional build defines or options required to build static library. Using Boost.Build system you can build the static library with a following command from libs/test/build directory:

`bjam` [-sTOOLS=<your-tool-name>] {-sBUILD=boost_prg_exec_monitor}

Also on Windows you can use the Microsoft Visual Studio .NET project file provided.

##### Dynamic library compilation

To build the dynamic library[2] you need to add BOOST_TEST_DYN_LINK to the list of macro definitions in the makefile. Using the Boost.Build system you can build the dynamic library with the following command from `libs/test/build` directory:

`bjam` [-sTOOLS=<your-tool-name>] {-sBUILD=boost_prg_exec_monitor}

Also on Windows you can use the Microsoft Visual Studio .NET project file provided.

| Important
For your program to successfully link with the dynamic library the flag BOOST_TEST_DYN_LINK needs to be defined both during dynamic library build and during your program compilation.

#### Support of the auto-linking feature

For the Microsoft family of compilers the Program Execution Monitor provides an ability to automatically select proper library name and add it to the list of objects to be linked with. To employ this feature you required to include either header `boost/test/prg_exec_monitor.hpp` or header `boost/test/included/prg_exec_monitor.hpp` By default the feature is going to be enabled. To disable it you have to define the flag BOOST_TEST_NO_LIB.

For more details on the auto-linking feature implementation and configuration you should consult the appropriate documentation.

#### Including the Program Execution Monitor directly into your program

If you prefer to avoid the standalone library compilation you have two alternative usage variants: you can either include all files that constitute the static library in your program's makefile or include them as a part of your program's source file. To facilitate the later variant the Program Execution Monitor implementation presents the header `boost/test/included/prg_exec_monitor.hpp` In both variants neither BOOST_TEST_DYN_LINK nor BOOST_TEST_NO_LIB are applicable. This solution may not be the best choice in a long run, since it requires the Program Execution Monitor sources recompilation for every program you use it with.

[1] There are varieties of make systems that can be used. To name a few: GNU make (and other make clones) and build systems integrated into IDEs (for example Microsoft Visual Studio). The Boost preferred solution is Boost.Build system that is based on top of bjam tool. Make systems require some kind of configuration file that lists all files that constitute the library and all build options. For example the makefile that is used by make, or the Microsoft Visual Studio project file, Jamfile is used by Boost.Build. For the sake of simplicity let's call this file the makefile.

[2] What is meant by the term dynamic library is a dynamically loaded library, alternatively called a shared library.