Boost logo

Boost Users :

From: Ross Boylan (ross_at_[hidden])
Date: 2005-12-26 18:50:10


When I try to link a test suite I get this:

ld: multiple definitions of symbol boost::test_tools::(anonymous namespace)::check_is_close
mspathCEntry_test.o definition of boost::test_tools::(anonymous namespace)::check_is_close in section (__DATA,__data)
ModelBuilder_test.o definition of boost::test_tools::(anonymous namespace)::check_is_close in section (__DATA,__data)
ld: multiple definitions of symbol boost::test_tools::(anonymous namespace)::check_is_small
mspathCEntry_test.o definition of boost::test_tools::(anonymous namespace)::check_is_small in section (__DATA,__data)
ModelBuilder_test.o definition of boost::test_tools::(anonymous namespace)::check_is_small in section (__DATA,__data)
LinearProduct_test.o definition of boost::test_tools::(anonymous namespace)::check_is_close in section (__DATA,__data)
LinearProduct_test.o definition of boost::test_tools::(anonymous namespace)::check_is_small in section (__DATA,__data)
.....

This is with boost 1.33 on Darwin/OS-X. The same code was building OK
with the 1.31 libraries (and 1.32 on linux, I think). I'm using libtool. Here's the makefile output before those errors (I've deleted some of the files on the command line to save space):

../libtool --mode=link --tag=CXX g++ -o test1 -g AbstractTimeStepsGenerator.o Coefficients.o -lboost_unit_test_framework -L/usr/local/lib/boost-1_33_1
g++ -o test1 -g AbstractTimeStepsGenerator.o Coefficients.o Covariates.o -Wl,-bind_\
at_load -lboost_unit_test_framework -L/usr/local/lib/boost-1_33_1

There are several copies of various flavors of the library lying around, but I don't think any are on the default library paths. So I think I'm only getting the one in /usr/local/lib/boost-1_33_1.

It looks as if each invocation of, e.g., BOOST_CHECK_CLOSE, is
generating a defiition for the symbols on which I'm getting
duplicates. But why would it do that?

Any suggestions, or ideas what might be going wrong?

Thanks.
Ross Boylan

Here are some possibly relevant details. Example code:
--------------------------------------------------
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <vector>

#include <boost/test/auto_unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>

using namespace boost::unit_test_framework;

#include "basic.h"
#include "Data.h"
#include "Model.h"
#include "mspath.h"

#include "main_test.h"

using namespace mspath;
using namespace std;
static Data * readInputDataFile() {
 //....
}
BOOST_AUTO_UNIT_TEST(CEntry){
  if (gOptions.input1() == 0) {
    BOOST_ERROR("Skipping mspathCEntry test. You need to specify an input file.");
    return;
  };
  cout.imbue(locale(""));
  Data* pdata = readInputDataFile();
  // .....
  BOOST_CHECK_CLOSE(results[0], 2835.43092, tol);
  // ....
}

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

Maybe I'm messing things up by rolling my own outer level code for the auto-unit tests:
-------------------------------------

#include "main_test.h"

#include <boost/test/auto_unit_test.hpp>

#include "basic.h"

// g for global
// It's ugly, but it works.
mspath::TestOptions mspath::gOptions;

/* The following function is just a slight modification to the usual
product of
#define BOOST_AUTO_TEST_MAIN
so that I can capture command line arguments.
See the top of the file for the meaning of those arguments.
*/
#if defined( BOOST_1_31)
// code for 1.31 and 1.32 snipped for brevity
#elif defined(BOOST_1_33)
boost::unit_test::test_suite*
init_unit_test_suite( int argc, char* argv[] ) {
    mspath::gOptions.init(argc, argv);
    boost::unit_test::auto_unit_test_suite_t* master_test_suite = boost::unit_test::auto_unit_test_suite();

   boost::unit_test::auto_unit_test_suite_t* master_test_suite = boost::unit_test::auto_unit_test_suite();

    boost::unit_test::const_string new_name = boost::unit_test::const_string( "BOOST_AUTO_TEST_MAIN" );

    if( !new_name.is_empty() )
        boost::unit_test::assign_op( master_test_suite->p_name.value, new_name, 0 );

    master_test_suite->argc = argc;
    master_test_suite->argv = argv;

    return master_test_suite;
}

#else
#error I do not know how to setup for this version of boost BOOST_VERSION
#endif
// etc
--------------------------------------------------------------


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