Boost logo

Boost :

Subject: [boost] [multi_index] multiple definition errors since 86597
From: Jürgen Hunold (jhunold_at_[hidden])
Date: 2013-11-12 02:18:24


Hi,

revision 86597 changed boost/multi_index/detail/bucket_array.hpp

Add were:
static const std::size_t sizes[];
static const std::size_t sizes_length;

member variables, initialised with

+template<>
+const std::size_t bucket_array_base<true>::sizes[]={
+ BOOST_PP_SEQ_ENUM(BOOST_MULTI_INDEX_BA_SIZES)

+template<>
+const std::size_t bucket_array_base<true>::sizes_length=
+ sizeof(bucket_array_base<true>::sizes)/
+ sizeof(bucket_array_base<true>::sizes[0]);
+

Now gcc (4.8.1) reports multiple definition errors when using multi_index in
different translation units:

file1.cpp.o:(.rodata+0x0): multiple definition of
`boost::multi_index::detail::bucket_array_base<true>::sizes_length'
file2.cpp.o:(.rodata+0x0): first defined here
file1.cpp.o:(.rodata+0x20): multiple definition of
`boost::multi_index::detail::bucket_array_base<true>::sizes'
file2.cpp.o:(.rodata+0x20): first defined here
CMakeFiles/graph_test.dir/main.cpp.o:(.rodata+0x0): multiple definition of
`boost::multi_index::detail::bucket_array_base<true>::sizes_length'
file2.cpp.o:(.rodata+0x0): first defined here
file3.o:(.rodata+0x20): multiple definition of
`boost::multi_index::detail::bucket_array_base<true>::sizes'
file2.cpp.o:(.rodata+0x20): first defined here

According to
http://stackoverflow.com/questions/1553854/template-static-variable

and my current c++ template knowledge, those instantiation belong to a .cpp
file to avoid this. This does not work for a header-only library, of course.

The current test suite does not catch this because it only contains single file
tests.

Yours,

Jürgen

-- 
* Dipl.-Math. Jürgen Hunold  ! 
* voice: ++49 4257 300       ! Fährstraße 1
* fax  : ++49 4257 300       ! 31609 Balge/Sebbenhausen
* jhunold_at_gmx.eu             ! Germany

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk