Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

multiply defined symbols in C++ anonymous namespace



The loader is complaining that some object files have multiply defined
symbols, even though the symbol in question is defined inside an unnamed
(anonymous) namespace and thus should be local to the translation unit
by the C++ standard.  I don't get this problem on other systems.

I worked around this with the -m flag to the linker ("This flag's use is
strongly discouraged" says the man page).

Is there a better solution?  Is this a known problem?

Details:

The software has not been refreshed recently, so is a little behind:
$ 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)

Extract of command line (with many .o files removed for brevity):
# That's GNU libtool, not Darwin's
../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
# It produces the following command
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

Representative errors:

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)

I have attempted to isolate the problem, but it has failed to reappear
in small test cases.  Here's my shortest recipe, which relies on Boost
1.33:
--------------------- 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);
}

----------------------------------------
Here's a piece of floating_point_comparison.hpp that is related to the
error:
struct check_is_close_t {
    // Public typedefs
    typedef bool result_type;

    template<typename FPT, typename PersentType>
    bool
    operator()( FPT left, FPT right, PersentType percentage_tolerance,
floating_point_comparison_type fpc_type = FPC_STRONG )
    {
        close_at_tolerance<FPT,PersentType> pred( percentage_tolerance,
fpc_type );

        return pred( left, right );
    }
};

// the actual error refers to the check_is_close object below
namespace {
check_is_close_t check_is_close;
}

-- 
Ross Boylan                                      wk:  (415) 514-8146
185 Berry St #5700                               email@hidden
Dept of Epidemiology and Biostatistics           fax: (415) 514-8150
University of California, San Francisco
San Francisco, CA 94107-1739                     hm:  (415) 550-1062

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.