"Go" How to use vs 2013 to publish an executable file that can run independently in Windows XP

Source: Internet
Author: User

Problem Description:

Write a program with VS2013 and run everything properly on this machine. However, if you put the exe file directly on another machine, it will appear:

Windows XP: Not a normal Win32 program

Window 7: Missing Msvcp120.dll

Is there a way to package the environment that the program needs to run so that it can be used on any Windows computer?

For your convenience, we created a simple console application project that directly

Quite simply, a console application that uses the C + + standard library performs the following effects in the native order in which the development environment is installed:

Real a masterpiece, we can't wait to send this to XP elder brother show off, never thought:

Installation force is not anti-XP elder brother ridicule: "negative split roll thick!" ”

Here we meet the problem of one of the problems, it is really puzzling, but a random search will have a solution:

Yes, in the project configuration properties, select the Platform tool as "Visual Studio 2013-windows XP (V120_XP)" To resolve the "invalid Win32 application" issue.

But we still have to know why, why?

What is the difference between a project's default Visual Studio (V120) and an executable file that is generated by Visual Studio 2013-windows XP (V120_XP), so that the former performs the same error on XP?

The most intuitive way is to compare the two version of the implementation of the difference between the file, we choose the PE (portable executable:32 bit or 64-bit Windows operating system using the executable program or dynamic link library file format) tool stud_pe PE file header structure comparison, It's easy to see the difference:

See the Red Fork where the two files are different, the other places almost no difference.

The PE file structure is another topic that we are not discussing in depth.

In these two places, as the name implies, it is easy to understand:

majorosversion, the (target) operating system major version number, the value of the file that selects the default platform toolset is 6, and the latter is 5.

minorosversion , the (target) operating system minor version number, the former is 0, the latter is 1.

majorsubsystemversion, (target) WIN32 subsystem major version number, the former is 6, the latter is 5.

minorsubsystemversion, (target) Win32 subsystem minor version number, the former is 0, the latter is 1.

Sum up: One is 6.0, one is 5.1.

Obviously 5.1 is the version number of XP, 6.0 is Vista chant?

Can we assume that the "platform toolset" generated by the project's default selection will not run in Windows version 6.0?

The test result: When I manually modified the 6.0 to 5.1, this file can be run in XP immediately, in fact, the value of major/minorosversion does not seem to play any role, Simply modifying the value of the xxxxxsubsystemversion will ensure that the program executes smoothly. Vice versa. Also found: In XP, instead of 5.1 can be, 5.2 and higher.

The understanding of this problem is still on the surface, but due to limited knowledge, we will no longer explore the deep meaning of these values in the PE structure. Of course, if there is Daniel pointing twos is better.

It's good now! We not only solved the problem of XP operation, but also understood the root of the problem. So let's go ahead and publish!

Send a new, XP, "5.1" version to XP elder brother:

I'll take a walk? You wait, I'll compile a release version ... Try:

Wipe? Not a good "Release"? You wait, not just a DLL file, I have here! I send you ...

I'm looking for a MSVCP120.DLL from my own system (Win 8.1 x64) C:\Wdinwos\system32 folder:

Yes, it's not funny. Take 64-bit DLL file to impersonate a 32-bit, can do? Re-go to the VS directory to pick up a correct 32-bit msvcp120.dll to complement:

Again, this time called MSVCR120.dll, not careful to see really did not recognize it. Continue to fill in:

Oh oh ah, finally to run correctly, but so embarrassed show how can make people happy up?

After some toss, somehow know is because of the lack of files, then the next release of the program to take these bottles and jars Ddll pack on the line? Yes, that's true, but it always feels unprofessional.

So, a normal solution is to have the target machine install visualc++redistributable Packages, as in the other answers forVisualStudio2013

The effect of this thing is:

installs run-time components that are required to run C + + applications that are generated using VisualStudio2013.

Simply observe which files are added to the XP system after installation:

In this way, the "runtime component" becomes intuitive and specific.

What are they all about? Let's take a look at our computer vs installation directory:

Through the path is easy to understand, this is about the VC redist (re-release) things, we go into the x86 look:

For a CRT (runtime Library), Mfc,mfcloc (localization file for MFC) and so on, let's look inside the CRT:

See the familiar of these two DLLs. In fact, you refer to the previous XP file of the image, those DLLs can be found here.

This is what Visual C + + redistributable includes, and each VS version is different. VS2013 corresponds to the.

Whether it is VS2013 or 2012 or 2008, the corresponding distribution package is not finished.

That's right. But we have to go on, at least, to look at how to make an executable file "standalone" running on XP.

Back to the project configuration, such as:

We see that the run-the-library item contains 4 choices.

Not much to say, we are simply rude simply to generate a comparison for each one:

Four versions, with corresponding names, multithreading (MT), Multi-threaded DLLs (MD), multithreaded Debugging (MTd), multithreaded debug DLLs (MDd), respectively.

Using the Stud_pe observation to compare their function import tables, it is found that:

1. Multithreaded dll (MD) and multithreaded debugging (MDD)

Both have imported 2 MSVCxxxx.dll (referred to as yellow arrows), but with a closer look, the Debug version (MDd) imports the MSVCP120D.dll and MSVCR120D.dll, which is one more than the non-debug (MD)-A-letter ' D '. Obviously this is the runtime library that is matched to the debug version. The release packages we previously installed were deployed without the D version and were used for the release version of the program.

by the way, MSVCP represents Microsoft Visual C + + (Plus), and MSVCR represents Microsoft Visual (no +) Runtime. One is the C + + runtime library .

2. Multithreading (MT) and Multi-threaded debugging (MTD)

Both seem to be the same, there is no MSVCP and MSVCR function Import, only Kernel32.dll. While observing the volume of these two files is much larger than MD or MDD, this formally does not require importing runtime library DLL functions because they compile the runtime libraries into their own files statically. This also means that they are not dependent on external runtime library DLL files when they are running.

So, want your EXE to run independently in XP:

1. Select the platform toolset as "Visual Studio 2013-windows XP (V120_XP)".

2. Select the runtime as "multithreaded/mt" or "Multithreaded Debug/MTd".

3, of course, if the use of MFC, the same should be set to "use MFC in a static library":

How to pack VC + + program with VS 2013? "Dr Yao's answer.

Above.

"Go" How to use vs 2013 to publish an executable file that can run independently in Windows XP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.