Re: [Boost-users] multiple definitions of symbol withRe: 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
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
I had the same problem with vc 7.1. If you add 'static' to all variables definitions in anonymous namespaces it works fine. For example instead of namespace { check_is_close_t check_is_close; } You can write namespace { static check_is_close_t check_is_close; // note 'static' keyword } Best regards, Perepelitsa Roman.
I had the same problem with vc 7.1.
Strange. I never had problems like this with vc7.1
If you add 'static' to all variables definitions in anonymous namespaces it works fine.
But anonimous namespace should do the trick itself! Gennadiy
Gennadiy Rozental wrote:
I had the same problem with vc 7.1.
Strange. I never had problems like this with vc7.1
If you add 'static' to all variables definitions in anonymous namespaces it works fine.
But anonimous namespace should do the trick itself!
Many compilers have such problems when using precompiled headers, take a look at boost/bind/placeholders.hpp for a list.
On Wed, Dec 28, 2005 at 09:58:54PM +0200, Peter Dimov wrote:
Gennadiy Rozental wrote:
I had the same problem with vc 7.1.
Strange. I never had problems like this with vc7.1
If you add 'static' to all variables definitions in anonymous namespaces it works fine.
But anonimous namespace should do the trick itself!
Many compilers have such problems when using precompiled headers, take a look at boost/bind/placeholders.hpp for a list.
GCC has reported bugs with precompiled headers and anonymous namespaces. However, I didn't request precompiled headers, and I'm not even sure that g++ 3.3 (which I used, though the Apple variant) has them. See gcc bug 10591 (which specifically mentions boost) for 3.4. One comment suggests it works in 4.0.0, but basically the same bug is also reported againt 4.0 (21179). There seems to be considerable uncertainty about the best way to fix the bug, and, probably as a result, not much sign of it being worked on. Ross P.S. Among the problems with the use of -m that I reported earlier is that erroneous duplicate symbols are likely to be missed, by the compiler because -m says let it pass, and by you because there may be a blizzard of bogus duplicate warnings. Presumably most of the other hazards of -m involve cases in which the "duplicate" symbols have different definitions. Since the symbols are being generated from the same include file in each compilation unit in my case (using boost test macros), that's not such a concern here.
On 12/27/05 10:52 PM, "Gennadiy Rozental"
I had the same problem with vc 7.1.
Strange. I never had problems like this with vc7.1
If you add 'static' to all variables definitions in anonymous namespaces it works fine.
But anonimous namespace should do the trick itself!
I don't think that the two concepts are identical. For a global object defined in a file, "static" limits that object to only be reachable to other items within that file. An object in the anonymous namespace has an unreachable name outside its file, but the object itself is still technically a program-wide global. -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
"Daryle Walker"
On 12/27/05 10:52 PM, "Gennadiy Rozental"
wrote: I had the same problem with vc 7.1.
Strange. I never had problems like this with vc7.1
If you add 'static' to all variables definitions in anonymous namespaces it works fine.
But anonimous namespace should do the trick itself!
I don't think that the two concepts are identical. For a global object defined in a file, "static" limits that object to only be reachable to other items within that file. An object in the anonymous namespace has an unreachable name outside its file, but the object itself is still technically a program-wide global.
Well, in this case it should lead to the same result: no duplicate symbols Gennadiy
participants (5)
-
Daryle Walker
-
Gennadiy Rozental
-
Perepelitsa Roman
-
Peter Dimov
-
Ross Boylan