I have some software that uses the BOOST matrix library UBLAS (1.33.1). This software compiles and links with GCC 4.1.1 (Debian Linux system - GNU ld) but gives linking errors with GCC 4.2: substitution.o:(.data+0x0): multiple definition of `_ZN5boost7numeric5ublas21scalar_divides_assignIT_T0_E8computedE' alignment.o:(.data+0x0): first defined here Here is from the definition of the static const member of a template class in boost/numeric/ublas/functional.hpp: template<class T1, class T2> struct scalar_divides_assign: public scalar_binary_assign_functor<T1, T2> { ... stuff ... }; template<class T1, class T2> const bool scalar_divides_assign<T1,T2>::computed = true; GCC 4.2, but not 4.1 actually emits this constant in the global data section. With 4.2: $ nm alignment.o | grep divides 0000000000000180 t _GLOBAL__I__ZN5boost7numeric5ublas21scalar_divides_assignIT_T0_E8computedE 0000000000000000 D _ZN5boost7numeric5ublas21scalar_divides_assignIT_T0_E8computedE With 4.1 neither of these two symbols (or is it one symbol, mentioned twice?) is emitted.
Here is some source code that exhibits the problem: ---------------- begin a.C ----------------- template<class T1, class T2> struct scalar_divides_assign { static const bool computed ; }; template<class T1, class T2> const bool scalar_divides_assign<T1,T2>::computed = true; ----------------- end ------------------ To see the problem do $ g++-4.2 -c a.C $ nm a.o | grep computed 0000000000000000 D _ZN21scalar_divides_assignIT_T0_E8computedE This symbol shouldn't be emitted, or at least not in this way.
Confirmed. (In reply to comment #1) > template<class T1, class T2> > const bool scalar_divides_assign<T1,T2>::computed = true; For this case above, nothing should be emitted.
It is only static const variables which are miss handled.
boostjam get segfault to build boost with gcc-4.2 > pwd /home/keti/download/boost_1_33_1 > > make ./tools/build/jam_src/bin.linuxx86/bjam -sPYTHON_ROOT=/usr -sPYTHON_VERSION=2.4 -sTOOLS=gcc /bin/sh: line 1: 27533
This also fails with 4.1 from SVN. The problem got introduced between 20060530 and 20060613.
(In reply to comment #4) > boostjam get segfault to build boost with gcc-4.2 I can confirm this, but this is a completely different issue. Unfortunately, I don't know if this is a bug in boost or gcc, but I suspect the former.
This was caused by this commit: 2006-06-04 Mark Mitchell <mark@codesourcery.com> PR c++/27819 * decl.c (cp_finish_decl): Process initializers for static data members with non-dependent initializers, even in templates.
*** Bug 28065 has been marked as a duplicate of this bug. ***
Subject: Bug 28016 Author: mmitchel Date: Sat Jun 17 01:11:34 2006 New Revision: 114739 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114739 Log: PR c++/28016 * decl.c (cp_finsh_decl): Do not emit uninstantiated static data members. PR c++/28016 * g++.dg/template/static26.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/static26.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.2.0.
*** Bug 28327 has been marked as a duplicate of this bug. ***
Mark, please apply to 4.1 branch also.
Subject: Bug 28016 Author: mmitchel Date: Wed Jul 12 07:22:47 2006 New Revision: 115365 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115365 Log: PR c++/28016 * decl.c (cp_finsh_decl): Do not emit uninstantiated static data members. PR c++/28016 * g++.dg/template/static26.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/static26.C Modified: branches/gcc-4_1-branch/gcc/cp/ChangeLog branches/gcc-4_1-branch/gcc/cp/decl.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Fixed in 4.1.2.
*** Bug 28599 has been marked as a duplicate of this bug. ***
*** Bug 28620 has been marked as a duplicate of this bug. ***