multiple definitions of symbol with Boost.Test

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 --------------------------------------------------------------

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
I remember seeing similar report recently. As it clear from error message linker complains about multiple definitions for symbols in anonymous namespace. This looks like compiler bug. If you know any workarounds please share them with us. Gennadiy

On Mon, 2005-12-26 at 19:25 -0500, Gennadiy Rozental wrote:
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
I remember seeing similar report recently. As it clear from error message linker complains about multiple definitions for symbols in anonymous namespace. This looks like compiler bug. If you know any workarounds please share them with us.
Gennadiy
The linker flag -m ("Don't treat multiply defined symbols as a hard error ... The first linked object is used ... This can still produce a resulting output file that is in error. This flag's use is strongly discouraged!") seems to work around the problem. I see lots of questions about multiply defined symbols errors for Mac OS X, but few answers. I reviewed gcc bugs with "namespace" in them and found nothing that looked relevant. I have attempted to reproduce the problem with small test cases that don't involve the Boost framework and have so far failed. So the error seems pretty subtle. I've attached sample files that give the error using boost (if you remove the -Wl,-m from LDFLAGS). Also note that using only a single file (a.o without b.o) does not produce the error. $ uname -a Darwin statcluster 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Macintosh powerpc $ g++ --version g++ (GCC) 3.3 20030304 (Apple Computer, Inc. build 1671) This not the latest release of the software or of OS X. I've manually added some \ where lines were broken by the mailer; the original had on long line in those spots. P.S. Does anyone know what's up with this warning, suppressed by no-long-double? /usr/local/include/boost-1_33_1/boost/type_traits/is_float.hpp:21: warning: use of `long double' type; its size may change in a future release --------------------- Makefile ------------------------------- CPPFLAGS += -I/usr/local/include/boost-1_33_1 CXXFLAGS += -Wno-long-double LDFLAGS += -L/usr/local/lib/boost-1_33_1 -lboost_unit_test_framework \ -Wl,-m go: t ./t t: a.o b.o ../mspath/src/libtool --mode=link --tag=CXX $(CXX) -o $@ $^ \ $(LDFLAGS) clean: rm *.o t ------------------------ a.cc------------------------------- #define BOOST_AUTO_TEST_MAIN #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> #include <boost/test/floating_point_comparison.hpp> BOOST_AUTO_UNIT_TEST(a){ BOOST_CHECK_CLOSE(4.1, 4.15, 20); } ------------------------- b.cc ------------------------ #include <boost/test/auto_unit_test.hpp> #include <boost/test/test_tools.hpp> #include <boost/test/floating_point_comparison.hpp> BOOST_AUTO_UNIT_TEST(b){ BOOST_CHECK_CLOSE(3.0, 3.0, .1); } -- Ross Boylan wk: (415) 514-8146 185 Berry St #5700 ross@biostat.ucsf.edu Dept of Epidemiology and Biostatistics fax: (415) 514-8150 University of California, San Francisco San Francisco, CA 94107-1739 hm: (415) 550-1062
participants (2)
-
Gennadiy Rozental
-
Ross Boylan