Building statically is not safe
Mantis Issue 452, reported by jmalik, assigned to rkanavath, created: 2012-01-03
One problem appear with the MersenneTwisterRandomGenerator : some failing tests on Windows (at least the ones using the ListSampleGenerator) are due to a wrong initialization of the MersenneTwisterRandomGenerator singleton.
In fact, the singleton is initialized in the TestDriver as part of the new "-testenv" option (which also initilizes the system random number generator) When inside the ListSampleGenerator, the instance of the MersenneTwisterRandomGenerator is different (the static Pointer inside the class is a different variable). This seems like a typical problem of static building/global variable : the problem appears with the application tests, where the TestDriver executable executes code from a DLL (via the plugin mechanism). Both the executable and the DLL get a different global variable.
There are some in-depth discussion in the itk-dev list about the issue of DLL build.
Essentially, if I understand well :
- ITK cannot be built as a DLL because of declspec missing from vxl
- The only possible thing is to compile ITKCommon as a DLL, and the rest as static. This is what is done when requiring BUILD_SHARED_LIB on windows for ITK.
- It is not safe to build plugins on top of statically built OTB (or ITK). In ITK they originally had problems with the ModifiedTime when building ITK plugins for VolView.
- It is probably not safe to build WrapITK/OTB-Wrapping on top of a static build (this is what we release as of now).
- I conclude that it is probably not safe to build the new OTB applications on top of a static build. We should try to enable BUILD_SHARED_LIB for ITK, to at least have ITKCommon as DLL (which includes itk::Object and the MersenneTwisterGenerator)
- Ultimately we should help the vxl folks to provide DLL support for vxl (but everyone says it is "not easy"...)
1325597321 - julienmThe (scary) itk-dev thread : http://www.itk.org/mailman/private/insight-developers/2011-March/017651.html
Note that the situation will be the same in ITK-4, since the incriminated change (http://review.source.kitware.com/#/c/419/) has been reverted, so there is still only ITKCommon built as DLL on Windows.
1325597588 - julienmAbout the failing tests, the action taken is to modify the "-testenv" part of the TestDriver to have the same init value than the constructor (121212 instead of 1234), and reupload new baselines for the SVM tests on linux.
We will at least have a coherent behavior between linux and windows, though it is more or less hiding a bug.
1325696366 - jguinetMersenneTwister seed have been set to 121212 in application wrappers
http://hg.orfeo-toolbox.org/OTB/rev/64145f29646d
1477054128 - grizonnetmWe're now able to build OTB with shared libs on all platforms