c/c++ runtime libraries from a developer point of view

If I am trying to make a program that will run on any Windows machine, what precautions do I need to take? I recently tried to run a simple program on another machine which generated the error "the program can't start because MSVCP140D.dll is missing from your computer. Try reinstalling the program to fix this problem." After doing some research, I found out a little bit more about the linking process and that a compiled program often does not have all the code necessary for it to run independently. It needs to reference code contained within the c/c++ runtime library (if the program is dynamically compiled rather than statically compiled?) which is provided by the operating system.

I am not writing this post to ask how to fix this one particular problem on this one machine. I want to know how to prepare solutions for these issues before they occur. What is it that a developer does to ensure their users do not have to update their runtime libraries themselves? I am guessing that this kind of thing is handled during the installation of a program. Is it possible that a mistake could be made during the update of a dynamically linked library (dll) file which might cause another program which had previously always worked find to no longer work correctly? How is this avoided?

My current IDE of choice is Visual Studio 2015. Would I use my IDE to create an installer executable? If I am on the right track in my thinking, how is this exe created such that it checks for and updates the dll files necessary for it to run? All of these questions are aimed towards learning how to write a program that runs on any Windows machine.
Compile it in release mode is a great start. Some programs need the VC redistributable package which you can bundle into an installer with your software or tell users to go get the latest one on their own depending on the audience.

The XXXXD libraries are DEBUG libraries. They do NOT exist on machines that lack Visual studio! The same files DO exist without the D on standard win machines, so compile in release fixes this.



Visual studio comes with a program that can reverse engineer an executable to find dlls that are needed to execute for you to bundle with it. This helps if you use things outside of the standard windows libraries -- though you really should know these for your program, since you had to manually add them to the project. A large project, it can become easy to lose one, so the tool is useful there.

Last edited on
The program I wrote to test this is just a simple program that performs calculations based on user input. It calculates the likelihood that given an n amount of people with different birthdays, two of them will have the same birthday.

It seems I am still having quite a bit of trouble with this topic, and I suppose in this post I am reneging my previous statement, "I am not writing this post to ask how to fix this one particular problem on this one machine" in a hope that knowing how to fix this one problem will give me the insight to fix future issues. Jonnin's post helped a lot. I had not realized I was in debug mode or even what debug mode is. I have since compiled in release mode, yet my program still generates errors on other Windows pc's. This error that I had written above:

"The program can't start because MSVCP140D.dll is missing from your computer. Try reinstalling the program to fix this problem."

has now become this error:

"The program can't start because MSVCP140.dll is missing from your computer. Try reinstalling the program to fix this problem."

At least the debug version is fixed even if the error has only altered form. But I also have gotten this error on another Windows PC:

"filename.exe is not a valid Win32 application."

To change Configuration to release mode I had used the configuration manager found in: Project -> Properties -> Configuration Manager (button at top right of window). There I verify that it uses Win32 as a platform. At that screen, I also have Build checked and Deploy unchecked.

I have begun to use Dependency Walker (version 2.2.6000 x64) as advised from this Microsoft page: https://docs.microsoft.com/en-us/cpp/ide/understanding-the-dependencies-of-a-visual-cpp-application

Since this is from the Visual Studio 2015 reference page, I wonder if Jonnin was alluding to Dependency Walker, although I had to download it. When opening the release version of my program in Dependency Walker, this error message appears:

"Errors were detected when processing filename.exe. See the long window for details"

The log window does not seem to be something very clearly named, so I assume it is the area which is aligned along the bottom of Dependency Walker. In this area are two listed errors in red. These errors are:

"Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module."

and:

"Error: Modules with different CPU types were found."

So, how am I doing, and what should I do as a developer to try to solve this issue of not being able to run a small program on 32bit Windows machines? If it makes a difference, the PC which has Visual Studio runs a 64 bit Windows operating system.

Last edited on
"filename.exe is not a valid Win32 application."

I got this message once when I tried to run a 64bit app on a 32bit PC.
I realize that is possible even though I did what I could to choose the correct Visual Studio settings, but it may also be possible that it is a problem with Dependency Walker. I found a lot of people saying that Dependency Walker has issues with interpreting files on a 64 bit system. Though that information could be outdated

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/393036

Last edited on
but it may also be possible that it is a problem with Dependency Walker.
Not in this case.
"filename.exe is not a valid Win32 application."
That's a Windows error message.
correct Visual Studio settings
What do you mean by this? X86 ?
What do you mean by this? X86 ? 

To create a release version Win32 executable, all I do is change the settings in the configuration manager, correct?

Project -> Properties -> Configuration Manager (button at top right of window)

The top is titled "Active solution configuration:" with options for Debug, Release, <New...>, <Edit...>. Across from that is "Active solution platform" with options for x64, x86, <New...>, <Edit...>.

I am assuming that this is not too much related to the build configuration, but in any case, I have this set to "Release" and "x86."

Under "Project contexts (check the project configurations to build or deploy):", the configuration manager lists Project, Configuration (with options for Debug, Release, <New...>, <Edit...>), Platform (with options for Win32, x64, <New...>, <Edit...>), Build (with a checkbox), and Deploy (with a checkbox).

I have selected Release, Win32, and I have selected the Build checkbox while the Deploy Checkbox is empty.
Last edited on
Topic archived. No new replies allowed.