Boost logo

Boost Users :

Subject: Re: [Boost-users] [test] Standalone use with multiple translation units?
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2016-05-12 10:58:39

Adam Nielsen <a.nielsen <at>> writes:

> Hi all,
> I am currently using Boost Test for my test code, however it is always
> an extreme headache trying to get Boost available on the target
> platforms I'm using. At the moment due to some environment
> restrictions it is just not possible to use a recent version of Boost,
> and since the Test library broke backwards compatibility with 1.59, my
> code will no longer compile on versions earlier than 1.59.

Which specific part?

> So I am looking to see whether I can avoid the need to compile the full
> Boost, and just pull in the bits that I need.
> The Boost Test docs say that the library can be used in single-header
> mode, however this only works when there is one translation unit.
> Since my tests are spread across dozens of files, I don't think this
> will work for me.
> Is there any way to use this single-header mode, and flag one file as
> the "primary" one, and others as extras, so that you can use
> single-header mode across multiple translation units?
> This would remove the need to do battle with getting the Boost
> libraries installed on various platforms, which would make it much
> easier and allow me to spend more time on my code, and less time on
> writing build scripts.

This is actually not that difficult it seems. In one translation unit define
BOOST_TEST_MODULE and use inlined header:

#define BOOST_TEST_MODULE single header multiunit test
#include <boost/test/included/unit_test.hpp>

in all other translation units just do this:

#include <boost/test/unit_test.hpp>



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at