Boost logo

Boost Users :

From: Raffi Enficiaud (raffi.enficiaud_at_[hidden])
Date: 2020-04-06 20:08:35


On 29.02.20 07:44, Andrew McFarlane via Boost-users wrote:
> Hi all,
>
> [snip]
>
> Here's the issue. Despite the fact that I have defined
> BOOST_TEST_NO_MAIN, it appears that my compiler is still generating 2
> objects files for the main executable entry:
>

Sorry for the late reply, I am not often on this list.

>
> As you might be wondering, all of my test translation units define
> BOOST_TEST_DYN_LINK, and none of them define BOOST_TEST_MODULE, as the
> documentation suggests.

The documentation does not exactly say that:
* BOOST_TEST_MODULE should be defined in one translation unit only
* BOOST_TEST_DYN_LINK should be defined in all translation units

See here:
https://www.boost.org/doc/libs/1_72_0/libs/test/doc/html/boost_test/adv_scenarios/shared_lib_customizations/entry_point.html

> I tried removing BOOST_TEST_NO_MAIN from main.cpp but that did not
> appear to do anything.

BOOST_TEST_NO_MAIN has effect only together with BOOST_TEST_MAIN (or
BOOST_TEST_MODULE) and BOOST_TEST_DYN_LINK. The static version of
boost.test has already a "main" defined.

The duplicate "main" can come from a wrong linking
("-lboost_unit_test_framework" on the link line may choose the static
version) or a duplicate "main" in your translation units.

Since compilation is always an issue in the C++ world, I wrote this some
time ago:

https://www.boost.org/doc/libs/1_72_0/libs/test/doc/html/boost_test/section_faq.html#boost_test.section_faq.how_to_set_up_a_cmake_project_us

Using a tool like CMake may make your life easier.

> I also tried removing the static and shared Boost.Unit lib files from my
> stage/lib directory and rebuilding only the shared version, and that did
> not work either.
>
> Also not that my g++ command does have the expected -L and -l flags for
> linking with Boost.Test:
>
> -L/usr/local/boost_1_72_0/stage/lib -lboost_unit_test_framework

I would rather help you out using the automatic registration. It should
support all the scenarios that you mentioned in another thread on this list.

It should be only a matter of doing this:

https://www.boost.org/doc/libs/1_72_0/libs/test/doc/html/boost_test/usage_variants.html#boost_test.usage_variants.shared_lib

Raffi


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net