[boost 1.39][Serialization] BOOST_CLASS_EXPORT_GUID macro failed to compile with C2888 error under MSVS.
Hi, All! Since I had no answer on my previous post, I'll try to clarify the problem here. So, I use a macro BOOST_CLASS_EXPORT_GUID from Boost.Serialization library. And everything was just fine until boost 1.39 came up to stage recently. Now the same very of my code, I've been using for so long (starting with boost 1.35 I guess), failed to compile under MS Visual Studio 2008 SP1. Compiler gives me an error error C2888: 'boost::archive::detail::`anonymous-namespace'::init_guid<CSomeClass>' : symbol cannot be defined within namespace 'anonymous-namespace'. The error occurs when export.hpp file (contains BOOST_CLASS_EXPORT_GUID) is included to stdafx.h (to precompiled headers) and the macro is used in any other cpp-file. I guess the problem is that 'init_guid' structure declaration (declared inside anonymous namespace) and definition appear in different translation units. So, it looks like there is a bug in boost 1.39 to me. Am I right? And what should I do? Should I file a bug? Thanks in advance.
Check the documentation regarding BOOST_CLASS_EXPORT and the best place to put it. Robert Ramey Vitaly Dolya wrote:
Hi, All!
Since I had no answer on my previous post, I'll try to clarify the problem here. So, I use a macro BOOST_CLASS_EXPORT_GUID from Boost.Serialization library. And everything was just fine until boost 1.39 came up to stage recently. Now the same very of my code, I've been using for so long (starting with boost 1.35 I guess), failed to compile under MS Visual Studio 2008 SP1. Compiler gives me an error error C2888: 'boost::archive::detail::`anonymous-namespace'::init_guid<CSomeClass>' : symbol cannot be defined within namespace 'anonymous-namespace'.
The error occurs when export.hpp file (contains BOOST_CLASS_EXPORT_GUID) is included to stdafx.h (to precompiled headers) and the macro is used in any other cpp-file. I guess the problem is that 'init_guid' structure declaration (declared inside anonymous namespace) and definition appear in different translation units.
So, it looks like there is a bug in boost 1.39 to me. Am I right? And what should I do? Should I file a bug?
Thanks in advance.
Thanks for the response, Robert!
Documentation didn't change a bit about it since boost 1.37, against
which I was able to compile my code.
Quote from the doc
(http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/special.html#exp...):
"Note that the implemenation of this functionality requires that the
|BOOST_CLASS_EXPORT| macro appear *after* and the inclusion of any
archive class headers for which code is to be instantiated.
...
||So, *the best way to use |BOOST_CLASS_EXPORT| is to include it in the
same module which implements the class*."
This is exactly as I did.
This is what I have for standalone exe-application:
In stdafx.h:
#include
Check the documentation regarding BOOST_CLASS_EXPORT and the best place to put it.
Sorry, I didn't read your post carefully enough. Try the following:
In stdafx.h: #include
#include #include #include
//In SomeClass.cpp:
#include "stdafx.h"
#include "SomeClass.h"
#include
Thanks for the response, Robert!
Documentation didn't change a bit about it since boost 1.37, against which I was able to compile my code. Quote from the doc (http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/special.html#exp...): "Note that the implemenation of this functionality requires that the
BOOST_CLASS_EXPORT| macro appear *after* and the inclusion of any archive class headers for which code is to be instantiated. ...
So, *the best way to use |BOOST_CLASS_EXPORT| is to include it in the same module which implements the class*."
This is exactly as I did. This is what I have for standalone exe-application:
In stdafx.h: #include
#include #include #include #include In SomeClass.cpp: #include "stdafx.h" #include "SomeClass.h" BOOST_CLASS_EXPORT(CSomeClass)
Did I miss something?
Robert Ramey wrote:
Check the documentation regarding BOOST_CLASS_EXPORT and the best place to put it.
Sorry for delayed answer, Robert. Yes, moving inclusion of export.hpp out of precompiled header helped. But the question remains... is it by design of Boost.Serialization, that I cann't include export.hpp explicitly or implicitly (through 3rd party library, for example) into application's precompiled header? Or should I claim Visual Studio compiler for the issue? Thanks for your help. Robert Ramey wrote:
Sorry, I didn't read your post carefully enough.
Try the following:
In stdafx.h:
#include
#include #include #include //In SomeClass.cpp: #include "stdafx.h" #include "SomeClass.h" #include
BOOST_CLASS_EXPORT(CSomeClass)
By design ? - lol - more like by default. The implemenation of BOOST_CLASS_EXPORT is relies on creating a single static singleton for each data type. Putting this in the header (inside an anonymous namespace?) results in creating multiple such records so it's not a singleton anymore. This leads to unintended consequences which I'm trying to figure out. Robert Ramey Vitaly Dolya wrote:
Sorry for delayed answer, Robert.
Yes, moving inclusion of export.hpp out of precompiled header helped. But the question remains... is it by design of Boost.Serialization, that I cann't include export.hpp explicitly or implicitly (through 3rd party library, for example) into application's precompiled header? Or should I claim Visual Studio compiler for the issue?
Thanks for your help.
Robert Ramey wrote:
Sorry, I didn't read your post carefully enough.
Try the following:
In stdafx.h:
#include
#include #include #include //In SomeClass.cpp: #include "stdafx.h" #include "SomeClass.h" #include
BOOST_CLASS_EXPORT(CSomeClass)
By design ? - lol - more like by default. The implemenation of BOOST_CLASS_EXPORT is relies on creating a single static singleton for each data type. Thank for the notice, but I was well aware of that. Actually my real question is what is it You were trying to solve with
Robert Ramey wrote: the patch, that broke my build: Index: export.hpp =================================================================== --- export.hpp (revision 51330) +++ export.hpp (revision 51360) @@ -160,6 +160,7 @@ namespace boost { \ namespace archive { \ namespace detail { \ + namespace { \ template<> \ struct init_guid< T > { \ static ::boost::archive::detail::guid_initializer< T > const \ @@ -170,7 +171,7 @@ ::boost::serialization::singleton< \ ::boost::archive::detail::guid_initializer< T > \ >::get_mutable_instance().export_guid(K); \ - }}} \ + }}}} \ /**/ #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
Putting this in the header (inside an anonymous namespace?)
No, I'm not trying to put BOOST_CLASS_EXPORT macro into any of my header
files.
I was trying to put
participants (2)
-
Robert Ramey
-
Vitaly Dolya