Differences between the x86, x64, Any CPU and Debug and Release of VS project platform, x86x64
I believe that for many comrades who are new to the packaging program, what are the differences between the x86, x64, and Any CPU project platforms and the solution configuration Debug and Release? This problem must have a lot of confusions, and even some old programmers who have been working for a long time are ambiguous. Of course, it took me a long time to understand the differences between them, so as to make a conclusion:
I. Differences between x86, x64, and Any CPUs
1.Simply put, the most direct difference between them is: The exe (Executable File) or dll (Dynamic Link Library) compiled on the x86 platform are 32-bit. Similarly, x64 corresponds to 64-bit. The Any CPU depends on the current operating system. If the operating system is 32-bit, the compiled program is 32-bit, And the compiled program is 64-bit.
2. if your startup project, that is, the main program (compiled as an exe file) is compiled on the x86 platform, and it depends on a project (or Dynamic Link Library) if it is compiled by the x64 platform, the system prompts "file or assembly cannot be loaded... Or one of its dependencies. Attempts to load programs with incorrect format ." Errors. This is because 32-bit programs cannot load 64-bit dll, and cannot call classes, methods, and objects. If the main program is compiled by the x64 platform, but the dll is x86? Answer .. No!Here, we can basically make sure that the dll and the main program generation platform can be consistent.. So there is a problem! If the main program is compiled by Any CPU, and the dll is compiled by the x86 or x64 platform, or the main program is compiled by the x86 or x64 platform, what about dll compiled by Any CPU? The correct answer is that the two are feasible under "special circumstances. Why is it "special? Because the first point (in the red font) also mentioned that Any CPU depends on the operating system, combined with the first half of the second point (in the red font, it is also feasible as long as the dll is consistent with the main program generation platform. So,It can be seen from the above: if the main program is compiled on Any CPU platform, then the platform for compiling dll must be consistent with the operating system for compiling the main program. If the main program is compiled on the x86 or x64 platform, the dll must be consistent with the main program. However, there is a special case: If the dll is compiled by Any CPU, the dll can be called by the 32-bit and 64-bit main programs.Why? Please refer to the third point.
3. Although the program compiled by Any CPU depends on the operating system,However, the dll compiled by Any CPU depends on the main program that calls it.If the main program is 32-bit, the dll is also 32-bit. If the main program is 64-bit, the dll is 64-bit. Therefore, the dll is generally compiled on Any CPU platform, while the main program is usually compiled on x86 platform.
When debugging on the x86 platform, you can modify the code while debugging, but not on the x64 platform (editing is enabled and continues ). For example:
The following message is displayed when you modify the code during debugging:
Conclusion: After learning about their differences, we know how to choose between them when packaging programs. Generally, the main program is compiled on the x86 platform and the dll is compiled on the Any CPU platform without knowing what type of operating system the customer's computer is or when both are used. If you know it is a 64-bit operating system, you can compile it on the x64 platform.
Ii. Differences between Debug and Release
Debug is usually called a Debug version. It contains debugging information without any optimization, so that programmers can Debug programs easily. Release is called a Release version. It is often optimized to optimize the code size and running speed, so that users can use it well. Therefore, Release is generally used to package and Release programs. In addition, the programs packaged by Release are relatively smaller.
In Release mode, you cannot modify the code while debugging (edit is enabled and continue ). The code modification prompt is as follows:
The above is my understanding of them. If you say something wrong, please correct them. If you have any questions, please add them!
Original article:
Http://www.timegowhere.com/post/about_vs_targetplatform.html