Shared Libraries
A number of attempts over the years have been made to produce shared libraries for iMSTK. I'm adding this issue here moreso to document its difficulty from experience of trying it, not so much to suggest it should be done. If one wanted to it would require huge changes.
1.) iMSTK exposes a significant amount of members from dependent libraries. Namely template ones such as the STL & Eigen. These libraries do not export classes as they are template libraries. You cannot export a class you do not even know the size of. So anywhere something like std::vector appears in a public or protected interface we have a problem. Solutions:
- Export a specialization of the template class, ie: export std::vector. This then locks in the ABI/binary interface (and things like size). Also presents dangers if you took it to another system whose ABI was different, for instance int was not the same size.
- Hide members that you can. By using pimpl where possible or make private and hide warning.
- Wrap the member class & export wrapped interface.
- Provide alternative method for passing if it just appears in a function (for ex: double* instead of a Vec2d).
2.) Singletons & statics. iMSTK has Logger as singleton & a few statics for ids. The concept of these get tricky when you think about a library that can be loaded at runtime, particular on windows for which the library can literally be shared. When should we create a second instance of the logger? When should we use the existing one?
- Conversely we have an issue if you try to link iMSTK (statically built) into two separate dll's. Then use both those dll's. You may experience issues regarding its singleton and statics.