Boost C++ Libraries: Ticket #12336: Add Hint to BOOST_ALL_DYN_LINK=1 to serialization library https://svn.boost.org/trac10/ticket/12336 <p> When you serialize a class over a pointer and the class is defined in a DLL, you need to register the key via BOOST_EXPORT_CLASS(xyz). </p> <p> But when you link static, you get two distinct serialization registries (extended_type_info) and the main executable cant serialize/deserialize the class in the DLL. </p> <p> When you compile with BOOST_ALL_DYN_LINK=1 and dynamicaly link to the boost libs, this ensures that there is just one registry (extended_type_info). </p> <p> So i would add this hint in the "Tips &amp; Tricks" section or in the page of the derived classes. </p> <p> BOOST_ALL_DYN_LINK=1 is important for the serialization. This ensures that there is just one extended_type_info registry. Otherwise the main executable cant de/serialize the objects in the DLL/so file. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12336 Trac 1.4.3 Robert Ramey Tue, 01 Nov 2016 22:24:43 GMT <link>https://svn.boost.org/trac10/ticket/12336#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12336#comment:1</guid> <description> <p> Hmmm - I believe that if you link static you should get only one registry. </p> <p> "When you compile with BOOST_ALL_DYN_LINK=1 and dynamicaly link to the boost libs, this ensures that there is just one registry (extended_type_info)." </p> <p> sound like you're using static linking and dynamic linking to deserialize. I don't see why that would be a problem, but I'd have to think about it (a lot) to really be sure. But I don't know if that's what you actually mean either. </p> </description> <category>Ticket</category> </item> <item> <author>georg@…</author> <pubDate>Wed, 02 Nov 2016 06:25:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12336#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12336#comment:2</guid> <description> <p> Dear Robert, </p> <p> yes, if i link all static (without explicit loaded plugin dll) i get one registry. </p> <p> We use a lot of virtual base classes in the executable and the implementations in dlls. The plugin is explicit loaded via "<a class="missing wiki">LoadLibrary</a>()" and the instance is created via an exported and "<a class="missing wiki">GetProcAddress</a>()ed" function. </p> <p> If i link static, the executable and the plugin dll, i get two registries. You can verify this if you check what extended_type_info object the BOOST_EXPORT_KEY_IMPLEMENT calls. I checked the this pointers of it. </p> <p> If i link all, the executable and the plugin with BOOST_ALL_DYN_LINK=1, then there is just one registry. </p> <p> A coworker run into this problem and got unregistered_class exceptions and he could not figure out why it occured. I knew this from the past and could help him. So i thought, why not add a hint in the documentation. </p> <p> Georg </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 02 Nov 2016 19:34:18 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/12336#comment:3 https://svn.boost.org/trac10/ticket/12336#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> "If i link static, the executable and the plugin dll, i get two registries. You can verify this if you check what extended_type_info object the BOOST_EXPORT_KEY_IMPLEMENT calls. I checked the this pointers of it. </p> <p> If i link all, the executable and the plugin with BOOST_ALL_DYN_LINK=1, then there is just one registry." </p> <p> Your idea to add it to the docs is not a bad one. I'll consider it. But the issue is much broader than that. In C++ if one builds with static libraries then link to a DLL, you can easily create a problem. This is because when one builds the app with static library, the linker then added all the C++ library stuff as static modules. Then you call a DLL. But the DLL -also written in C++ will also cal C++ library functions. Then either of the following occurs. If the DLL is linked statically, you've got the C++ function twice in the code. This is a problem for things like strtok and other stuff which carry an internal state. Or the DLL links to a C++ runtime and now you've go two different versions of the C++ library in your code. You can manage all this if you're careful - but its way too easy to create a failure which is almost impossible to find - as you've found out. </p> <p> So if you want write a good explanation of all this, I'll consider adding it to the tips and tricks section. </p> <p> Robert Ramey </p> Ticket