3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Customizing the module's entry point</title>
5 <link rel="stylesheet" href="../../../boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../../index.html" title="Boost.Test">
8 <link rel="up" href="../static_lib_customizations.html" title="Static-library variant customizations">
9 <link rel="prev" href="../static_lib_customizations.html" title="Static-library variant customizations">
10 <link rel="next" href="init_func.html" title="Customizing the module's initialization function">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="../static_lib_customizations.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../static_lib_customizations.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="init_func.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h4 class="title">
27 <a name="boost_test.adv_scenarios.static_lib_customizations.entry_point"></a><a class="link" href="entry_point.html" title="Customizing the module's entry point">Customizing
28 the module's entry point</a>
29 </h4></div></div></div>
31 In the static library variant, customizing the main entry point is quite
32 troublesome, because the definition of function <code class="computeroutput"><span class="identifier">main</span></code>
33 is already compiled into the static library. This requires you to rebuild
34 the <span class="emphasis"><em>Unit Test Framework</em></span> static library with the defined
35 symbol <a class="link" href="../../utf_reference/link_references/link_boost_test_no_main.html" title="BOOST_TEST_NO_MAIN"><code class="computeroutput"><span class="identifier">BOOST_TEST_NO_MAIN</span></code></a>. In the Boost
36 root directory you need to invoke command
38 <pre class="programlisting"><span class="special">></span> <span class="identifier">b2</span> <span class="special">--</span><span class="identifier">with</span><span class="special">-</span><span class="identifier">test</span> <span class="identifier">link</span><span class="special">=</span><span class="keyword">static</span> <span class="identifier">define</span><span class="special">=</span><a class="link" href="../../utf_reference/link_references/link_boost_test_no_main.html" title="BOOST_TEST_NO_MAIN"><code class="computeroutput"><span class="identifier">BOOST_TEST_NO_MAIN</span></code></a> <span class="identifier">define</span><span class="special">=</span><a class="link" href="../../utf_reference/link_references/link_boost_test_alternative_init_macro.html" title="BOOST_TEST_ALTERNATIVE_INIT_API"><code class="computeroutput"><span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span></code></a> <span class="identifier">install</span>
40 <div class="warning"><table border="0" summary="Warning">
42 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
43 <th align="left">Warning</th>
45 <tr><td align="left" valign="top"><p>
46 This removal of entry point definition from the static library will affect
47 everybody else who is linking against the library. It may be less intrusive
48 to switch to the <a class="link" href="../shared_lib_customizations.html" title="Shared-library variant customizations">shared
49 library usage variant</a> instead.
53 In one of the source files, you now have to define your custom entry point,
54 and invoke the default <a class="link" href="../test_module_runner_overview.html" title="Test module runner">test
55 runner</a> <code class="computeroutput"><span class="identifier">unit_test_main</span></code>
56 manually with the default <a class="link" href="../test_module_init_overview.html" title="Test module's initialization">initialization
57 function</a> <code class="computeroutput"><span class="identifier">init_unit_test</span></code>
58 as the first argument. There is no need to define <a class="link" href="../../utf_reference/link_references/link_boost_test_no_main.html" title="BOOST_TEST_NO_MAIN"><code class="computeroutput"><span class="identifier">BOOST_TEST_NO_MAIN</span></code></a> in your source
59 code, but you need to define <a class="link" href="../../utf_reference/link_references/link_boost_test_alternative_init_macro.html" title="BOOST_TEST_ALTERNATIVE_INIT_API"><code class="computeroutput"><span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span></code></a>
62 <div class="informaltable"><table class="table">
70 In <span class="bold"><strong>exactly one</strong></span> file
81 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="identifier">name</span>
82 <span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span>
83 <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
85 <span class="comment">// entry point:</span>
86 <span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">argv</span><span class="special">[],</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">envp</span><span class="special">[])</span>
87 <span class="special">{</span>
88 <span class="keyword">return</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">unit_test_main</span><span class="special">(</span><span class="identifier">init_unit_test</span><span class="special">,</span> <span class="identifier">argc</span><span class="special">,</span> <span class="identifier">argv</span><span class="special">);</span>
89 <span class="special">}</span>
93 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
95 <span class="comment">//</span>
96 <span class="comment">// test cases</span>
97 <span class="comment">//</span>
99 <span class="comment">//</span>
100 <span class="comment">// test cases</span>
101 <span class="comment">//</span>
106 <div class="note"><table border="0" summary="Note">
108 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
109 <th align="left">Note</th>
111 <tr><td align="left" valign="top"><p>
112 The reason for defining <a class="link" href="../../utf_reference/link_references/link_boost_test_alternative_init_macro.html" title="BOOST_TEST_ALTERNATIVE_INIT_API"><code class="computeroutput"><span class="identifier">BOOST_TEST_ALTERNATIVE_INIT_API</span></code></a>
113 is described <a class="link" href="../obsolete_init_func.html" title="The obsolete initialization function">here</a>.
117 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
118 <td align="left"></td>
119 <td align="right"><div class="copyright-footer">Copyright © 2001-2019 Boost.Test
121 Distributed under the Boost Software License, Version 1.0. (See accompanying
122 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
127 <div class="spirit-nav">
128 <a accesskey="p" href="../static_lib_customizations.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../static_lib_customizations.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="init_func.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>