Boost logo

Boost Users :

From: Neutrino (neutrino_sunset_at_[hidden])
Date: 2008-08-24 14:37:02


Hi.

I'd like a little guidance regarding the use of <boost/test/unit_test.hpp>
please. I'm using mingw--gcc-3.4.5 with CodeBlocks 8.02. I'm dynamically
linking to boost_unit_test_framework-mgw34-d-1_36.dll via
boost_unit_test_framework-mgw34-d-1_36.lib. I have BOOST_TEST_DYN_LINK
defined and I've worked out that I need to have #define BOOST_TEST_MODULE
<whatever> defined in one source file prior to #include
<boost/test/unit_test.hpp>.

That's all good so far and the following example compiles and runs.

------------------------

// Main.cpp
#define BOOST_TEST_MODULE Main
#include <boost/test/unit_test.hpp>

------------------------

// Test1.cpp
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test1)
{
        BOOST_CHECK(true);
}

------------------------

// Test2.cpp
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test2)
{
        BOOST_CHECK(true);
}

------------------------

My problem arises when I try to include <boost/test/unit_test.hpp> in a
precompiled header.

------------------------

// Pch.h
#ifndef PCH_H_INCLUDED
#define PCH_H_INCLUDED

// Boost headers.

#include <boost/test/unit_test.hpp>

#endif // PCH_H_INCLUDED

------------------------

// Main.cpp
#define BOOST_TEST_MODULE Main
#include <boost/test/unit_test.hpp>

------------------------

// Test1.cpp
#include "Pch.h"

BOOST_AUTO_TEST_CASE(test1)
{
        BOOST_CHECK(true);
}

------------------------

// Test2.cpp
#include "Pch.h"

BOOST_AUTO_TEST_CASE(test2)
{
        BOOST_CHECK(true);
}

------------------------

The compiler is exiting with no errors but no output binary is produced. The
build log reports:

Info: resolving vtable for boost::unit_test::unit_test_log_tby linking to
__imp___ZTVN5boost9unit_test15unit_test_log_tE (auto-import)
obj\Debug\Mnf\Mnf.EventTest.o: In function
`ZN5boost6detail17sp_counted_impl_pINS_9unit_test9ut_detail16callback0_impl_tINS3_6unusedEPFvvEEEED0Ev':
F:/My
Documents/Development/Libraries/boost_1_36_0/boost/detail/sp_counted_base_gcc_x86.hpp:(.bss+0x0):
multiple definition of `boost::unit_test::(anonymous
namespace)::unit_test_log'
obj\Debug\Mnf\Mnf.BoostFunctionBindTest.o:F:/My
Documents/Development/Libraries/boost_1_36_0/boost/detail/sp_counted_base_gcc_x86.hpp:(.bss+0x0):
first defined here
obj\Debug\Mnf\Mnf.EventTest.o: In function
`ZN5boost6detail17sp_counted_impl_pINS_9unit_test9ut_detail16callback0_impl_tINS3_6unusedEPFvvEEEED0Ev':
F:/My
Documents/Development/Libraries/boost_1_36_0/boost/detail/sp_counted_base_gcc_x86.hpp:(.bss+0x4):
multiple definition of `boost::test_tools::(anonymous
namespace)::dummy_cond'
obj\Debug\Mnf\Mnf.BoostFunctionBindTest.o:F:/My
Documents/Development/Libraries/boost_1_36_0/boost/detail/sp_counted_base_gcc_x86.hpp:(.bss+0x4):
first defined here
obj\Debug\Pch.o: In function
`ZN5boost9unit_test13test_observer12test_abortedEv':
F:/My
Documents/Development/Libraries/boost_1_36_0/boost/test/test_observer.hpp:(.bss+0x0):
multiple definition of `boost::unit_test::(anonymous
namespace)::unit_test_log'
obj\Debug\Mnf\Mnf.BoostFunctionBindTest.o:F:/My
Documents/Development/Libraries/boost_1_36_0/boost/detail/sp_counted_base_gcc_x86.hpp:(.bss+0x0):
first defined here
obj\Debug\Pch.o: In function
`ZN5boost9unit_test13test_observer12test_abortedEv':
F:/My
Documents/Development/Libraries/boost_1_36_0/boost/test/test_observer.hpp:(.bss+0x4):
multiple definition of `boost::test_tools::(anonymous
namespace)::dummy_cond'
obj\Debug\Mnf\Mnf.BoostFunctionBindTest.o:F:/My
Documents/Development/Libraries/boost_1_36_0/boost/detail/sp_counted_base_gcc_x86.hpp:(.bss+0x4):
first defined here

I do not understand why the header file <boost/test/unit_test.hpp> objects
to being included via a precompiled header file in this way. The following
simple case also works fine.

------------------------

// Pch.h
#ifndef PCH_H_INCLUDED
#define PCH_H_INCLUDED

// Boost headers.

#define BOOST_TEST_MODULE Main
#include <boost/test/unit_test.hpp>

#endif // PCH_H_INCLUDED

------------------------

// Main.cpp
#include "Pch.h"

BOOST_AUTO_TEST_CASE(test1)
{
        BOOST_CHECK(true);
}

------------------------

I'll start having a look at the Boost source and see if I can work out what
I'm doing wrong, but if anyone can see a problem with what I'm trying to do
here I'd be grateful if they could point it out for me.

Thanks
Neutrino.

-- 
View this message in context: http://www.nabble.com/Problem-with-%3Cboost-test-unit_test.hpp%3E-in-precompiled-header.-tp19132545p19132545.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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