Home > The Program Execution Monitor > Compilation
PrevNext

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:
同 boost 大多數其它完全實在在頭文件的庫相比,Program Execution Monitor 的編譯鏈接需要額外的步驟。 Program Execution Monitor 提供選項能夠在程序中生成並鏈接獨立的庫 (built and link with a standalone library)直接包含實現文件 (include the implementation directly)。 如果選擇使用庫,Program Execution Monitor 頭文件實現了自動鏈接支持 (auto-linking support), 下面的標籤用來配置 Program Execution Monitor 庫和自己程序的編譯:

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].
如果你選擇將你的程序鏈接到獨立的庫,需要首先生成它。 要將所有的 C++ 文件 (.cpp) 生成獨立的庫,組成 Program Execution Monitor 實現 (implementation) 需要列在 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.
Boost.Build 系統使用的 makefile 在 libs/test/build 目錄。 Program Execution Monitor 可以作為靜態庫 (static) 動態庫 (dynamic) 生成。

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:
生成靜態庫並不需要額外的生成定義或選項。 使用 Boost.Build 系統可以用下面的命令從 libs/test/build 目錄生成靜態庫:

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

Also on Windows you can use the Microsoft Visual Studio .NET project file provided.
在 Windows 上你可以使用 Microsoft Visual Studio .NET 的工程文件。

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:
要生成靜態庫[2], 需要在 makefile 的宏列表中添加 BOOST_TEST_DYN_LINK。 使用 Boost.Build 系統你可以用下面的命令從 libs/test/build 目錄生成動態庫:

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

Also on Windows you can use the Microsoft Visual Studio .NET project file provided.
在 Windows 上可以使用 Microsoft Visual Studio .NET 工程文件。

[Important] 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.
你的程序要正確鏈接動態庫,標籤 BOOST_TEST_DYN_LINK 需要在生成動態庫和編譯自己程序時都定義。

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.
對於 Microsoft 族的編譯器,Program Execution Monitor 提供了自動選擇合適的庫名稱並將其加入到鏈接的對象列表中的功能。 要使用這個特性,需要包含 boost/test/prg_exec_monitor.hppboost/test/included/prg_exec_monitor.hpp 頭文件。 這個特性默認被開啟。如果想要關閉,需要定義標籤 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.
如果你想避免獨立庫的編譯,你有兩種選擇:在程序的 makefile 中加入組成靜態庫的所有文件,或者將它們作為源文件的一部分。 為了簡化後一種選擇,Program Execution Monitor 的實現提供了頭文件 boost/test/included/prg_exec_monitor.hpp。 在兩種情況下 BOOST_TEST_DYN_LINKBOOST_TEST_NO_LIB 都可以應用。 這個解決方案在長時間使用中可能並不適用,因為它要求在每個使用的程序中都重新編譯 Program Execution Monitor 的源文件。



[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.
有多種生成系統可以使用。例如:GNU make (包括其它 make 的拷貝) 以及和 IDE 結合的生成系統 (例如 Microsoft Visual Studio)。 Boost 推薦的解決方案是 Boost.Build 系統,基於 bjam 工具。 生成系統需要一些類型的配置文件列出組成庫的所有的文件和生成選項。 例如 makefile 用於 make,或者 Microsoft Visual Studio 工程文件,Jamfile 用於 Boost.Build。 出於簡化的目的,我們都稱為 makefile。

[2] What is meant by the term dynamic library is a dynamically loaded library, alternatively called a shared library.
動態庫是動態加載庫 (dynamically loaded library),或者叫做共享庫 (shared library)


PrevUpHomeNext