Static Linked Visual C++ Runtimes


Is there a way to set a up a cocos2d-x v4 pc project so that it can be compiled with the visual c++ runtimes compiled in as static libs, not as runtime dll’s.

I’ve had a bit of luck using the cmake option to set the msvc runtime library but it seems to blow up with the external libs?

Anyone had any success with achieving this? Is there some internal cocos2d-x option - perhaps CC_STATIC in CocosConfigDefine.cmake?

This would make PC distribution easier as there would be no dependency on the visual c++ runtime distributables, saving users the need to run extra installs.


I think this should be possible. I haven’t tried. I think @R101 is a good resource for advice on this.

@R101 whatcha think?

I don’t recall seeing any CMake option in the CocosConfigDefine.cmake related to statically link the runtime libraries, but there is no reason you can’t add it yourself in the root CMakeLists.txt of your application.

Aside from that, it’s perhaps not a good idea to statically link to the VC++ runtimes, because if any serious issues are found in the runtimes, then the users won’t get the update unless you release a new version of your application. If instead your application uses dynamic linking and the VC++ runtime distribution, then users would automatically get updates to the VC++ runtimes via Windows update.

Check the information here to see if it will help:

From what I can see, it’s the /MT switch that allows you to statically link the runtime libraries, so in CMake it would be:

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
or if you just want the release version of the libraries for all builds (release or debug):

Thanks for the quick responses.

That’s pretty much the way I’m doing things along with setting cmake_policy(SET CMP0091 NEW) to enable the CMAKE_MSVC_RUNTIME_LIBRARY config for anyone else trying this.

Checking the generated cocos2d-x project all the /MT flags appear to be set and the code compiles fine but blows up on linking specifically with libchipmunk and libbullet with :

mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value MTd_StaticDebug'

So I’m guessing these libs, and probably others that will fail linking after these errors are fixed, are supplied within cocos2d-x as prebuilt with dynamic linking set which causes the link mismatch errors.

Also these libs don’t appear in my project in the external folder of my project which is confusing :confused:

Is there a way to build all of these external prebuilt dependencies in cocos2d-x so they can be built using the static runtime flag?

Thanks again

You can download the library source and build any library yourself. Check here:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.