On Thu, Jun 18, 2015 at 4:24 PM, Dan Liew <d...@su-root.co.uk> wrote: > Hi, > > On 18 June 2015 at 12:16, Robert Dailey <rcdailey.li...@gmail.com> wrote: >> On Thu, Jun 18, 2015 at 12:02 PM, Dan Liew <d...@su-root.co.uk> wrote: >>>> Can you explain what you mean by "strong" and "weak" symbols? >>> >>> >>> Google is your friend >>> >>> https://en.wikipedia.org/wiki/Weak_symbol >>> >>> http://stackoverflow.com/questions/2290587/gcc-style-weak-linking-in-visual-studio >> >> Normally Google is my friend, but today it hates me. Because no such >> feature exists for MSVC that I saw. > > The stackoverflow suggests it is possible for MSVC. > > Thinking about it some more I think what I'm suggesting is the wrong > approach. If you're writing C++ code you should avoid coupling your > classes to allow dependency injection (i.e. you pick how classes are > coupled at run time not at compile time). If your classes are written > with dependency injection in mind then you don't need the weak symbol > stuff I was talking about.
I managed to find MSVC information outside of the SO question (No, I never skimmed through it sufficiently to find any information directly there on it). Apparently MSVC will prioritize symbols in .OBJ files over those found in .LIB without any warnings or errors. So only special case logic is needed for GCC on Linux (the #pragma weak <symbol> format). I agree with the principle of runtime dependency injection. It's necessary when mocking across library boundaries. However, my two main concerns: 1) Complexity overhead (Objects will now become more complex to construct, as dependencies must be fulfilled externally). This appears to be a common concern with dependency injection, however factories and reasonable defaults normally will help counter the issue. 2) Compile time polymorphism for dependency injection (i.e. templates) may not be an option. Template classes are not compiled into static libs, so there may even be a way to do this. However slightly related to #1, it forces a class to become a template when it otherwise would not need to be one (remedy would be an alias serving a default template argument). I think I can make this work, thanks to the fine suggestions here. Much appreciated guys. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake