Statically linking Visual Studio dlls to dynamically linked sfml project

Multi tool use
Multi tool use


Statically linking Visual Studio dlls to dynamically linked sfml project



I have an SFML, Visual Studio project that needs to be linked using the /MT option in the runtime library settings because I want to avoid having to install the microsoft redistributable to every computer that runs the program.



When I added sfml to the project, it appeared to work fine in its dynamic form. However, when I tried the program on another computer, it told me that I had missing visual studio dlls.



I understand that in order to link sfml statically to the project I would have to rebuild it with different runtime libraries. My question is why would it be able to correctly compile with sfml dynamically linked to the project and have the project set to /MT at the same time if it failed to statically link the necessary visual studio dlls to the project?





My problem is that dynamically linking sfml and statically linking the runtime libraries results in the program requiring the redistributable somehow. I cant install the redistributable to every computer I wish to use it on for reasons outside my control.
– The Great Sauron
Jul 2 at 2:28






Oh, ok I get it. Thanks for your help. If you post that as an answer Ill mark it as correct. :)
– The Great Sauron
Jul 2 at 5:18




2 Answers
2



After discussions in the comments, we agreed on this:



It is not uncommon to link some libraries statically and still link dynamically to others, like the language runtime. So the compiler should not complain about this.



To get a single executable containing everything, the program must link all libraries statically and they must, in turn, also link statically to all their dependencies.



Otherwise, if we have one dynamic library, like SFML, that library will likely in turn link dynamically to the runtime library. And that will still require the runtime DLLs.



This is possible, you'll just have to build SFML yourself (which isn't that hard to do).



Just make sure that you set the CMake variable SFML_USE_STATIC_STD_LIBS to TRUE so SFML uses the static runtime, no matter whether you're actually creating static or shared libraries.


SFML_USE_STATIC_STD_LIBS


TRUE



In short:


cmake -DSFML_USE_STATIC_STD_LIBS=TRUE -DCMAKE_INSTALL_PREFIX=C:/path/where/to/install/SFML C:/path/to/the/cloned/source/repository


INSTALL






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

rWL2C W QVpK PIf Gt6875,cGpMy3drsk,qhYTrk1rZla
P,aDOpG45W0axcRfIeypXaPHdw 5ZwO nvWT5J8t4oSRzv4,8 VJx,zSgg,VkLmxz QO YdWgS4gj,CgVmwX

Popular posts from this blog

Rothschild family

Cinema of Italy