[Boost.Serialization] Exception during serialization through base pointer DLL & EXE
Hi, On our platform (VS2019, Windows x64, Boost 1.77) an exception occurs during the serialization of an instance through its base pointer. This error is systematic and I was able to reproduce w/ a minimal use test (cf. enclosed archive). This use case includes a solution w/ a DLL project and EXE project. The EXE project is a simple unit-test. On my platform when I execute the executable, I trigger an exception from Boost.Serialization ("unregistered void cast class cpe::derived_t<-class cpe::object_t"). I tried every recommandation that we can find on SO and Boost mailing lists without success. To be accurate, I prefer to mention that we are using Boost.Serialization Static Library flavor. Any help would be appreciated. -- Marc Viala
On 6/03/2022 00:21, Marc Viala wrote:
On our platform (VS2019, Windows x64, Boost 1.77) an exception occurs during the serialization of an instance through its base pointer. This error is systematic and I was able to reproduce w/ a minimal use test (cf. enclosed archive). This use case includes a solution w/ a DLL project and EXE project. The EXE project is a simple unit-test. On my platform when I execute the executable, I trigger an exception from Boost.Serialization ("unregistered void cast class cpe::derived_t<-class cpe::object_t"). I tried every recommandation that we can find on SO and Boost mailing lists without success. To be accurate, I prefer to mention that we are using Boost.Serialization Static Library flavor.
This last sentence is the cause of your problem. If you wish to use static libraries, then you must use *only* static libraries (or at least anything that is in a static library cannot appear in your DLL ABI at all). If you wish to use Boost.Serialization in your DLL ABI then you must use the shared library variant only, such that both your EXE and DLL use a common implementation. Otherwise they will each have independent copies of the singletons. If your DLL boundary exists only for unit testing, then switch your DLL to a static library instead. If it exists for consuming by applications other than just your unit test, then you have to ensure that Boost types and concepts do not cross the DLL boundary if you want to use them as a static library.
Thank you very much for your reply Gavin. This is what we had assumed after all our tests and we have now the confirmation. I am just wondering if it will be valuable to explain this corner case in the Boost.Serialization documentation. Best regards, Marc Le lun. 7 mars 2022 à 01:34, Gavin Lambert via Boost-users < boost-users@lists.boost.org> a écrit :
On 6/03/2022 00:21, Marc Viala wrote:
On our platform (VS2019, Windows x64, Boost 1.77) an exception occurs during the serialization of an instance through its base pointer. This error is systematic and I was able to reproduce w/ a minimal use test (cf. enclosed archive). This use case includes a solution w/ a DLL project and EXE project. The EXE project is a simple unit-test. On my platform when I execute the executable, I trigger an exception from Boost.Serialization ("unregistered void cast class cpe::derived_t<-class cpe::object_t"). I tried every recommandation that we can find on SO and Boost mailing lists without success. To be accurate, I prefer to mention that we are using Boost.Serialization Static Library flavor.
This last sentence is the cause of your problem.
If you wish to use static libraries, then you must use *only* static libraries (or at least anything that is in a static library cannot appear in your DLL ABI at all).
If you wish to use Boost.Serialization in your DLL ABI then you must use the shared library variant only, such that both your EXE and DLL use a common implementation. Otherwise they will each have independent copies of the singletons.
If your DLL boundary exists only for unit testing, then switch your DLL to a static library instead. If it exists for consuming by applications other than just your unit test, then you have to ensure that Boost types and concepts do not cross the DLL boundary if you want to use them as a static library. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Marc Viala
On 7/03/2022 20:35, Marc Viala via Boost-users wrote:
Thank you very much for your reply Gavin. This is what we had assumed after all our tests and we have now the confirmation.
I am just wondering if it will be valuable to explain this corner case in the Boost.Serialization documentation.
That's pretty much standard for all libraries on Windows, at least (Linux is a bit weirder; it may or may not be the case depending on how the symbol visibility is set -- essentially Windows defaults to hidden symbols and Posix defaults to visible symbols, though there has been a push recently to make it behave more like Windows). You can often get away with it when there aren't singletons involved, but there can still be ABI problems if you have version mismatches between each side.
participants (2)
-
Gavin Lambert
-
Marc Viala