Hi guys, hi Laurent,
I wanted to ask (again) about changing the way SFML links to dependencies. It has been discussed a bit in this thread already:
http://en.sfml-dev.org/forums/index.php?topic=7602.0When talking with some guys in #SFML (irc.boxbox.org) and ##MinGW (Freenode), and remembering the issues we had with SFGUI (double definitions at the linker stage, i.e. importing GLEW 2 times), I felt like bringing this back to the table again.
Let's identify the problem first: SFML itself links to libraries it's using, also internally only. Those libraries are provided as pre-built static libraries in the releases and also in the source snapshots/SCM. When building SFML, it links those dependencies in, statically, i.e. the archives (/static libs) are packed into the final SFML library.
I think the main purpose of that is to ease using SFML, so that the user doesn't has to link to GLEW, OpenAL and all the other dependencies.
However, there are some problems that shouldn't be ignored and that can lead to severe errors and crashes under certain circumstances: If the target executable (i.e. the user program) imports the same dependecies that are already being defined in SFML, clashes might happen (especially when using different GLEW versions). Also the developer can't exchange the dependency, e.g. to upgrade to a later version. Both together can lead to severe problems when, for example, the ABI changes. In general the ODR (one-defition rule) seems to be violated.
The solution would be to throw away all target_link_libraries() calls in SFML's CMake scripts. However I'm not 100% sure if that works with MSVC too. Such a change would indeed require the end-user to link to all the deps himself, but in my opinion telling/teaching them the right way is better than going for an easy approach with accepting that fatal bugs might happen.