MSVCR11.dll missing on other machines, but when i build application i linked it staticly!

Started by
3 comments, last by BaneTrapper 11 years ago

Hello.

I made a application in Visual studio 2012.

I had additionally installed Microsoft visual c++ 1012 redistributable(x86).

In project options -> C/C++ -> Code Generation -> Run time library -> (For release is) Multi-threaded(/MT)

When i ship the application to others they get error "MSVCR11.dll is missing..."

My application is 32bit console application. The user experiencing the issue is running Win7 without "Microsoft visual c++ 1012 redistributable(x86)." instaled.

After the user installed Microsoft visual c++ 1012 redistributable(x86). the error didn't pop up, and the application run as expected.

Do i need to ship something in the folder with the application.exe?

What may i be doing wrong?

Advertisement
Sounds like you are using a method from the dynamic library MSVCR11.dll in your code.
These methods are loaded dynamically at runtime so it expects the appropriate DLL file to be there when your application runs. You can resolve your error in a few ways:

1) By running the appropriate "Microsoft visual c++ 1012 redistributable(x86)" installer as you mention on the machine trying to run your code. This will install the DLL to windows appropriately for later use by your application Do not just include the dll with your application, it needs to be properly installed on the system. You will want to match x86 and x64 installer versions appropriately with how your code is compiled (which will likely be x86 or 32 bit). Usually this is included as part of the install process for your application.
2) I believe there is an option to compile the methods "statically" instead of using "dynamic" libraries in the linker options. I'm not sure if this is true in the newer version of MSVS or not, but may be worth looking into. This would make it so you don't need to use the "Microsoft visual c++ 1012 redistributable(x86)" installer as the methods are compiled into your executable instead.
3) Figure out what methods are used in that MSVCR11.dll and avoid using them in your code. You can use something like http://www.dependencywalker.com/ to figure this out.
Hope this helps.
Edit: I just realized you are already linking statically. There may be a library dependency in there still you don't realize maybe form a 3rd party library you are using. I'd try dependency walker to confirm this.
Boo ya grandma.. boo ya!

A fairly common mistake which can cause this is using a mix of dll's and static linkage. While you might be telling your specific target to link statically against MSVCRT it is still possible that you are using a library which tries to use it dynamically. Just an example, perhaps you use an XML parser, it may even be built as a static library, but it could still be set to reference the dll version of MSVCRT. So, when linked into your application your code is using the static link against MSVCRT and the Xml library but the Xml library is inserting the metadata which refers to the DLL version, thus causing the indirect requirement.

In order to track this down, you might want to do a Google for Dependency Walker. With this you can open your executable and track all the various dependencies. If it shows the dll version of MSVCRT directly from your program, check the above mentioned external libraries. (And your own libraries if you perhaps missed setting one to the correct linkage.) If that is not the problem, keep digging down to see the source of the dependency.

If you are already compiling with Multi-threaded (/MT) option, you will also need to make sure that ALL the libraries you use are also compiled with /MT. That usually means getting the source and compiling yourself.

Can get tedious.

Easier to distribute your game with C++ runtime installer or required DLL in the same directory.

A fairly common mistake which can cause this is using a mix of dll's and static linkage.

Well that is the solution to the problem.

Shame i didn't see that written anywhere i was looking for all day...

Thanks!

I did build sfml2.0 as dynamic/shared... i hope building it static will fix the missing .dll error.

This topic is closed to new replies.

Advertisement