
Hello. I'm trying to use the boost serialization library. I'm using Visual C++ 7.1 under Windows 2000. The Boost.Serialization library seems excellent, and its ease of use is great. However I'm having two problems with it: First Problem. Here's the code: cdx::shrec_script script(""); std::ofstream ofs("compiled_shrec.txt"); boost::archive::text_oarchive oa(ofs); oa << script; // close archive ofs.close(); I get an error from boost static_assert, static_assert.hpp (below). Line 437 of regexconv.hpp refers to the "oa << script;" statement. If I copy the script archive to a new const object: const cdx::shrec_script temp_script(script); And try to serialize the temp_script object, the error goes away, and everything (seems to) work okay. I don't really have a problem with copying it, although it is inconvenient, in order to get this to work. However, the real problem is when I try to de-serialize the class: cdx::shrec_script script(""); std::ifstream ifs("compiled_shrec.txt"); boost::archive::text_iarchive oa(ifs); ia << script; // close archive ifs.close(); I get the same error (below). This is the big problem, because obviously the object needs to be non-const to be altered with the new data. I tried doing the same trick as above to get it to work (copy to a const object), but I still get the STATIC_ASSERTION_FAILURE error. c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(551) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>' with [ x=false ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(551) : see reference to class template instantiation 'boost::STATIC_ASSERTION_FAILURE<x>' being compiled with [ x=false ] c:\Boost\include\boost-1_33\boost\archive\basic_text_oarchive.hpp(78) : see reference to function template instantiation 'void boost::archive::save<Archive,T>(Archive &,T &)' being compiled with [ Archive=boost::archive::text_oarchive, T=cdx::shrec_script ] c:\Boost\include\boost-1_33\boost\archive\detail\interface_oarchive.hpp(76) : see reference to function template instantiation 'void boost::archive::basic_text_oarchive<Archive>::save_override<T>(T &,int)' being compiled with [ Archive=boost::archive::text_oarchive, T=cdx::shrec_script ] regexconv.hpp(437) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive<Archive>::operator <<<cdx::shrec_script>(T &)' being compiled with [ Archive=boost::archive::text_oarchive, T=cdx::shrec_script ] Second Problem. I'm getting linker errors when trying to compile Boost.Serialization with multi threaded runtimes in VC71. Linker errors are pasted at the bottom of this message. Somebody had told me that boost-1.31 and up headers now provide the proper #pragma for linking with the correct static library automagically, but I tried adding the #pragma's myself anyway. I'm not sure exactly what library to link with (there are lots of libbost_serialization*.lib files), so I tried each one. Each produced different results with different linker errors ranging from multiply defined symbols to unresolved externals. One did compile, however: #pragma comment(lib, "libboost_serialization-vc71-s.lib") But the program crashes as soon as it is run with the error (an uncaught exception): This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Press any key to continue I'm assuming this may be related to the fact that the 's' in libboost_serialization-vc71-s.lib means that the lib is compiled for single threads, and this is a multi threaded program. But of course, I'm probably wrong. Any light anybody can shed on either of these issues would be greatly appreciated! Thanks! Brett aftli@optonline.net Compiling... boost_test.cpp Linking... Creating library Release/boost_test.lib and object Release/boost_test.exp boost_test.obj : error LNK2001: unresolved external symbol "private: static char const * const boost::serialization::detail::extended_type_info_typeid_0::type_info_key" (?type_info_key@extended_type_info_typeid_0@detail@serialization@boost@@0PBD B) boost_test.obj : error LNK2019: unresolved external symbol "protected: virtual __thiscall boost::archive::detail::basic_iarchive::~basic_iarchive(void)" (??1basic_iarchive@detail@archive@boost@@MAE@XZ) referenced in function "public: virtual __thiscall boost::archive::detail::common_iarchive<class boost::archive::text_iarchive>::~common_iarchive<class boost::archive::text_iarchive>(void)" (??1?$common_iarchive@Vtext_iarchive@archive@boost@@@detail@archive@boost@@U AE@XZ) boost_test.obj : error LNK2019: unresolved external symbol "protected: virtual __thiscall boost::archive::detail::basic_oarchive::~basic_oarchive(void)" (??1basic_oarchive@detail@archive@boost@@MAE@XZ) referenced in function "public: virtual __thiscall boost::archive::detail::common_oarchive<class boost::archive::text_oarchive>::~common_oarchive<class boost::archive::text_oarchive>(void)" (??1?$common_oarchive@Vtext_oarchive@archive@boost@@@detail@archive@boost@@U AE@XZ) boost_test.obj : error LNK2019: unresolved external symbol "protected: void __thiscall boost::serialization::extended_type_info::self_register(void)" (?self_register@extended_type_info@serialization@boost@@IAEXXZ) referenced in function "private: __thiscall boost::serialization::extended_type_info_typeid<class gps_position const
::extended_type_info_typeid<class gps_position const >(void)" (??0?$extended_type_info_typeid@$$CBVgps_position@@@serialization@boost@@AAE @XZ)
boost_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_oarchive_impl<class boost::archive::text_oarchive>::save(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?save@?$text_oarchive_impl@Vtext_oarchive@archive@boost@@@archive@boost@@QA EXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: static void __cdecl boost::archive::save_access::save_primitive<class boost::archive::text_oarchive,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class boost::archive::text_oarchive &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$save_primitive@Vtext_oarchive@archive@boost@@V?$basic_string@DU?$char_tr aits@D@std@@V?$allocator@D@2@@std@@@save_access@archive@boost@@SAXAAVtext_oa rchive@12@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z ) boost_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::text_iarchive_impl<class boost::archive::text_iarchive>::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?load@?$text_iarchive_impl@Vtext_iarchive@archive@boost@@@archive@boost@@QA EXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: static void __cdecl boost::archive::load_access::load_primitive<class boost::archive::text_iarchive,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class boost::archive::text_iarchive &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??$load_primitive@Vtext_iarchive@archive@boost@@V?$basic_string@DU?$char_tr aits@D@std@@V?$allocator@D@2@@std@@@load_access@archive@boost@@SAXAAVtext_ia rchive@12@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z ) boost_test.obj : error LNK2019: unresolved external symbol "protected: __thiscall boost::archive::detail::basic_oarchive::basic_oarchive(void)" (??0basic_oarchive@detail@archive@boost@@IAE@XZ) referenced in function "protected: __thiscall boost::archive::detail::common_oarchive<class boost::archive::text_oarchive>::common_oarchive<class boost::archive::text_oarchive>(void)" (??0?$common_oarchive@Vtext_oarchive@archive@boost@@@detail@archive@boost@@I AE@XZ) boost_test.obj : error LNK2019: unresolved external symbol "protected: __thiscall boost::archive::detail::basic_iarchive::basic_iarchive(void)" (??0basic_iarchive@detail@archive@boost@@IAE@XZ) referenced in function "protected: __thiscall boost::archive::detail::common_iarchive<class boost::archive::text_iarchive>::common_iarchive<class boost::archive::text_iarchive>(void)" (??0?$common_iarchive@Vtext_iarchive@archive@boost@@@detail@archive@boost@@I AE@XZ) boost_test.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> >
::~basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> > >(void)" (??1?$basic_text_oprimitive@V?$basic_ostream@DU?$char_traits@D@std@@@std@@@a rchive@boost@@QAE@XZ) referenced in function "public: virtual __thiscall boost::archive::text_oarchive_impl<class boost::archive::text_oarchive>::~text_oarchive_impl<class boost::archive::text_oarchive>(void)" (??1?$text_oarchive_impl@Vtext_oarchive@archive@boost@@@archive@boost@@UAE@X Z)
boost_test.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::basic_text_iprimitive<class std::basic_istream<char,struct std::char_traits<char> >
::~basic_text_iprimitive<class std::basic_istream<char,struct std::char_traits<char> > >(void)" (??1?$basic_text_iprimitive@V?$basic_istream@DU?$char_traits@D@std@@@std@@@a rchive@boost@@QAE@XZ) referenced in function "public: virtual __thiscall boost::archive::text_iarchive_impl<class boost::archive::text_iarchive>::~text_iarchive_impl<class boost::archive::text_iarchive>(void)" (??1?$text_iarchive_impl@Vtext_iarchive@archive@boost@@@archive@boost@@UAE@X Z)
boost_test.obj : error LNK2019: unresolved external symbol "protected: void __thiscall boost::archive::basic_text_iarchive<class boost::archive::text_iarchive>::load_override(struct boost::archive::class_name_type &,int)" (?load_override@?$basic_text_iarchive@Vtext_iarchive@archive@boost@@@archive @boost@@IAEXAAUclass_name_type@23@H@Z) referenced in function "private: virtual void __thiscall boost::archive::detail::common_iarchive<class boost::archive::text_iarchive>::vload(struct boost::archive::class_name_type &)" (?vload@?$common_iarchive@Vtext_iarchive@archive@boost@@@detail@archive@boos t@@EAEXAAUclass_name_type@34@@Z) boost_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::detail::basic_iarchive::load_object(void *,class boost::archive::detail::basic_iserializer const &)" (?load_object@basic_iarchive@detail@archive@boost@@QAEXPAXABVbasic_iserializ er@234@@Z) referenced in function "public: static void __cdecl boost::archive::detail::load_non_pointer_type<class boost::archive::text_iarchive,class gps_position>::load::invoke(class boost::archive::text_iarchive &,class gps_position &)" (?invoke@load@?$load_non_pointer_type@Vtext_iarchive@archive@boost@@Vgps_pos ition@@@detail@archive@boost@@SAXAAVtext_iarchive@45@AAVgps_position@@@Z) boost_test.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::archive::detail::basic_oarchive::save_object(void const *,class boost::archive::detail::basic_oserializer const &)" (?save_object@basic_oarchive@detail@archive@boost@@QAEXPBXABVbasic_oserializ er@234@@Z) referenced in function "public: static void __cdecl boost::archive::detail::save_non_pointer_type<class boost::archive::text_oarchive,class gps_position>::save::invokex(class boost::archive::text_oarchive &,class gps_position const &)" (?invokex@save@?$save_non_pointer_type@Vtext_oarchive@archive@boost@@Vgps_po sition@@@detail@archive@boost@@SAXAAVtext_oarchive@45@ABVgps_position@@@Z) boost_test.obj : error LNK2001: unresolved external symbol "struct boost::archive::version_type const boost::archive::ARCHIVE_VERSION" (?ARCHIVE_VERSION@archive@boost@@3Uversion_type@12@B) boost_test.obj : error LNK2001: unresolved external symbol "char const * const boost::archive::ARCHIVE_SIGNATURE" (?ARCHIVE_SIGNATURE@archive@boost@@3PBDB) boost_test.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> >
::basic_text_oprimitive<class std::basic_ostream<char,struct std::char_traits<char> > >(class std::basic_ostream<char,struct std::char_traits<char> > &,bool)" (??0?$basic_text_oprimitive@V?$basic_ostream@DU?$char_traits@D@std@@@std@@@a rchive@boost@@QAE@AAV?$basic_ostream@DU?$char_traits@D@std@@@std@@_N@Z) referenced in function "protected: __thiscall boost::archive::text_oarchive_impl<class boost::archive::text_oarchive>::text_oarchive_impl<class boost::archive::text_oarchive>(class std::basic_ostream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$text_oarchive_impl@Vtext_oarchive@archive@boost@@@archive@boost@@IAE@A AV?$basic_ostream@DU?$char_traits@D@std@@@std@@I@Z)
boost_test.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::basic_text_iprimitive<class std::basic_istream<char,struct std::char_traits<char> >
::basic_text_iprimitive<class std::basic_istream<char,struct std::char_traits<char> > >(class std::basic_istream<char,struct std::char_traits<char> > &,bool)" (??0?$basic_text_iprimitive@V?$basic_istream@DU?$char_traits@D@std@@@std@@@a rchive@boost@@QAE@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@_N@Z) referenced in function "public: __thiscall boost::archive::text_iarchive_impl<class boost::archive::text_iarchive>::text_iarchive_impl<class boost::archive::text_iarchive>(class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int)" (??0?$text_iarchive_impl@Vtext_iarchive@archive@boost@@@archive@boost@@QAE@A AV?$basic_istream@DU?$char_traits@D@std@@@std@@I@Z)
Release/boost_test.exe : fatal error LNK1120: 17 unresolved externals Build Time 0:01

I don't know whether your using 1.32 or CVS version. I also don't know the larger context which would be helpful to explain the issue here. First Problem ========= The general idea is that one use save(Archive & ar, const X & x, ...){ ar << x.members ; } load(Archive & ar, X &x, ...){ ar >> x.members; } OR serialize(Archive & ar, X &x ){ ar & x; } This permits const correctness in that Saving doesn't (and better not because of tracking) change the state of x while Loading will in change it. So a) if you're going to use the << operator make sure the operand is a const reference b) if you're going to use the >> operator make sure the operand is NOT a const reference c) if you're goingto use & it shouldn't be a const. d) If you can't easily do this, DONT make a copy use a cast instead. If you make a copy it will break tracking of redundant saves. Second Problem =========== This pain it the neck is resolved with the next version (1.33) where the serialization library implemetns auto_linking of the correct library for platforms which support it> For now you have to figure it out yourself.
there are a lot of libraries
the ones called ..wserialization are for wide characters - exclude them for now. That should leave only static and dynamic multi-thread versions.
so I tried each one (library). Each produced different results with different linker errors ranging from multiply defined symbols to unresolved externals. One did compile, however:
I assume you meant one did LINK however - great.
But the program crashes as soon as it is run with the error (an uncaught exception):
I'm assuming this may be related to the fact that the 's' in libboost_serialization-vc71-s.lib means that the lib is compiled for single threads, and this is a multi threaded program. But of course, I'm probably wrong.
Hmm using the s.lib with a mulit-threaded CRT library would do it. Try the folloing. a) Try to build and execute the demo program. b) Assuming your using the VC IDE. Look at the *.vcproj files that are included with the package and compare them with your own. c) once you've been able to get the demo to build in your environment, move on to your own app. Good luck. Robert Ramey

Robert Ramey wrote:
I don't know whether your using 1.32 or CVS version. I also don't know the larger context which would be helpful to explain the issue here.
I originally was using 1.32, but when I started having problems with Serialization (about three days ago), I pulled boost off of CVS .
This permits const correctness in that Saving doesn't (and better not because of tracking) change the state of x while Loading will in change it.
You offer great insight on this, it makes sense. I'll try it out as soon as possible and give a reply to let you know how I made out.
Second Problem =========== This pain it the neck is resolved with the next version (1.33) where the serialization library implemetns auto_linking of the correct library for platforms which support it>
Well, just an FYI then, the CVS version still doesn't work when using multi threaded CRTs. :) As I mentioned above, I'm using a 3 day old CVS. I can deal with it, though.
Hmm using the s.lib with a mulit-threaded CRT library would do it. Try the folloing.
a) Try to build and execute the demo program. b) Assuming your using the VC IDE. Look at the *.vcproj files that are included with the package and compare them with your own. c) once you've been able to get the demo to build in your environment, move on to your own app.
I'll take a look, but I've done the following: 1. Create a new project (I'm using Visual Studio .NET 2003) 2. Insert a new source file, paste the (first) example from the Serialization documentation. 3. Change to multi threaded CRTs. The project won't link. The only .lib file that the project will link up with is the serialization*s.lib (the exact name escapes me right now). This isn't to say I probably can't work around this (somehow). And although I *really* hate to scream "bug" and have it be a user error, I am starting to think there may actually be a problem with the library. Thanks again for your insight, it's much appreciated. Brett

Note that the test matrix indicates all demos and examples are compiling, linking, and executing without error with the current CVS and VC 7.1. Exceptions are shared_ptr (which is being addressed) and one of the demos - portable_archive (DLL version) which can't work with VC7.1 Of course these are all built with the bjam system. These problems occur from time to time and up until now have always been traced to a difference in setup between the bjam and the VC 7.1 IDE. I expect that will be the case as well here. One option is to use the solution in the vc7ide directory along with the projects for all the test and demos. Try to build one of the demos from there. (There might be some changes to be made for local directorynames etc). When you've got that, you can compare to your own IDE options. Good luck Robert Ramey
This isn't to say I probably can't work around this (somehow). And although I *really* hate to scream "bug" and have it be a user error, I am starting to think there may actually be a problem with the library.
Thanks again for your insight, it's much appreciated.
Brett
participants (2)
-
Brett Gmoser
-
Robert Ramey