BSD

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • multiply defined symbols in C++ anonymous namespace

    0 answers - 3726 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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++
    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 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 +=
    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 $(CXX) -o $@ $^ \
    $(LDFLAGS)
    clean:
    rm *.o t
    a.cc
    #define BST_AUTTEST_MAIN
    #include <boost/test/auto_unit_test.hpp>
    #include <boost/test/test_tools.hpp>
    #include <>
    BST_AUTUNIT_TEST(a){
    BST_CHECK_CLSE(4.1, 4.15, 20);
    }
    b.cc
    #include <boost/test/auto_unit_test.hpp>
    #include <boost/test/test_tools.hpp>
    #include <>
    BST_AUTUNIT_TEST(b){
    BST_CHECK_CLSE(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_STRNG )
    {
    close_at_tolerance<FPT,PersentTypepred( 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;
    }

Re: multiply defined symbols in C++ anonymous namespace


max 4000 letters.
Your nickname that display:
In order to stop the spam: 1 + 0 =
QUESTION ON "BSD"

EMSDN.COM