Difference between Debug and Release and x86, x64, Any CPU in Visual Studio &&&& Difference between Debug and Release, _WIN32 and _WIN64 in VS Difference between Debug and Release and x86, x64, Any CPU in Visual Studio

I thought these irrelevant Debug and Release and x86, x64, Any CPU almost killed people.

After reading the following blog post, I was afraid. No wonder I switched the mode and the program was passed. . . .

 

Reprinted:

1.https: //www.cnblogs.com/xxn-180727/p/9442992.html

2.https://www.cnblogs.com/netserver/p/11106130.html

 

 

1. Debug and Release

1. Difference   

    Debug-debug version, the generated .exe contains a lot of debugging information, if the package is sent directly, it is relatively large;

    Release-release version

2. How to distinguish between Debug compilation and Release compilation

    Debug compilation has macro definition _DEBUG, if _DEBUG is defined in the code, it means debug compilation, otherwise it is release

    Compile.

    Eg:    #ifdef _DEBUG
    ........ // Executed during debugging, not executed during release
    #else
    ........     //
 

Second, _WIN32 and _WIN64

1. Definition

  _WIN32 is a 32-bit compilation; _WIN64 is a 64-bit compilation.

  The reason for compiling in different digits is to improve the versatility of the software. First, let ’s understand some common sense:

  • If the computer operating system has a different number of bits, the bytes occupied by the basic data types in the code are also different.

     For example: under 32-bit platform, long long is 8 bytes (64-bit), and under 64-bit platform, long is 8 bytes (64-bit)

  • 64-bit operating systems can theoretically run 32-bit and 64-bit software, while 32-bit operating systems can only run 32-bit software.

       So how to make the software run on different platforms? The method is the macro definition:

Eg:# ifdef _WIN64
        typedef long int  int64_t;
        # else
        _extension_
        typedef long long int int64_t;

2. How to distinguish between 32-bit compilation and 64-bit compilation

       Under Win32 configuration, _WIN32 is defined, _WIN64 is not defined. Under x64 configuration, both are defined.

     It can be understood that 32-bit does not support 64-bit, and 64-bit is compatible with 32-bit. In short, under VC, _WIN32 must be defined.

    Therefore, _WIN64 is used to determine whether the compilation environment is 32-bit or 64-bit, and WIN32 or _WIN32 can be used to
     Determine whether it is a Windows system (for cross-platform programs).
      Generally VS selects win32 console program and compiles with win32, because the compatibility is better, you can operate in 32-bit
     Runs on the system, it can also run on a 64-bit operating system.
3. Application
1 #ifdef _WIN64 // Description is 64-bit compilation
 2 typedef long long intptr_t; 3 #else 
4 typedef _W64 int intptr_t; 5 #endif

 

 

 

 

 

 

The difference between Debug and Release and x86, x64, Any CPU in Visual Studio

 

The difference between Debug and Release in Visual Studio:

      In Visual Studio, there are two compilation modes: Debug and Release. This is also the default two ways. When creating a new project, these two modes already exist for selection.

      Debug is usually called the debug version, it contains debugging information, and does not make any optimization, which is convenient for programmers to debug the program.
      Release is called the release version, and it is often optimized, so that the program is optimal in code size and running speed, so that users can use it well.

SO:
      Generally, Release is used to package and release programs, because Release has made more optimizations and runs faster, which is suitable for deployment after the project is completed. In addition, the program files packaged by Release will be relatively small. The Debug mode is more suitable for development and debugging. Namely: Use Debug mode when developing and debugging, and Release mode for packaging and publishing programs.

 

 

The difference between x86, x64 and Any CPU in Visual Studio:

1. Simply put, the most direct difference between them is that the exe (executable file) or dll (dynamic link library) compiled by the x86 platform are all 32-bit. 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. If the operating system is 64-bit, the compiled program is a 64-bit program.

2. If your startup project, the main program (compiled as an exe file) is compiled under the x86 platform, and a project (or dynamic link library) it depends on is compiled by the x64 platform, it will An error such as "Failed to load file or assembly ... or one of its dependencies. Attempt to load a program with an incorrect format." This is because 32-bit programs cannot load 64-bit dlls, nor can they call classes, methods, and objects.
Conversely, what if the main program is compiled from the x64 platform and the dll is x86? answer. . Not good!
Speaking of which, basically one thing can be determined: as long as the generation platform of the dll and the main program are consistent .
Then the question is coming! What if the main program is compiled by Any CPU, and the dll is compiled by x86 or x64 platform, or the main program is compiled by x86 or x64 platform, and the dll is compiled by Any CPU? The correct answer is that both are feasible under "special circumstances". Why is it a "special case"? Because the first point is also mentioned, Any CPU depends on the operating system, and as mentioned in the second point, as long as the dll and the main program generation platform are the same, it is also feasible. Therefore, it can be seen from the above that if the main program is compiled under the Any CPU platform, the platform for compiling the dll must be consistent with the operating system for compiling the main program. If the main program is compiled under 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 is this? Please see the third point.

3. Although the program compiled by Any CPU depends on the operating system, the dll compiled by Any CPU depends on the main program that calls it. That is, if the main program is 32-bit, the dll is also 32-bit. If the main program is 64-bit, then the dll is 64-bit. Therefore, the dll is generally compiled using the Any CPU platform, and the main program (exe) is generally compiled using the x86 platform.

Summary: After understanding the difference between them, we know how to choose when we package the program. Generally speaking, when it is unclear what type of operating system the customer's computer is, or both, the main program is compiled on the x86 platform, and the dll is compiled on the Any CPU platform . If it is clear that it is a 64-bit operating system, then all can be compiled on the x64 platform.

The difference between Debug and Release in Visual Studio:

      In Visual Studio, there are two compilation modes: Debug and Release. This is also the default two ways. When creating a new project, these two modes already exist for selection.

      Debug is usually called the debug version, it contains debugging information, and does not make any optimization, which is convenient for programmers to debug the program.
      Release is called the release version, and it is often optimized, so that the program is optimal in code size and running speed, so that users can use it well.

SO:
      Generally, Release is used to package and release programs, because Release has made more optimizations and runs faster, which is suitable for deployment after the project is completed. In addition, the program files packaged by Release will be relatively small. The Debug mode is more suitable for development and debugging. Namely: Use Debug mode when developing and debugging, and Release mode for packaging and publishing programs.

 

 

The difference between x86, x64 and Any CPU in Visual Studio:

1. Simply put, the most direct difference between them is that the exe (executable file) or dll (dynamic link library) compiled by the x86 platform are all 32-bit. 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. If the operating system is 64-bit, the compiled program is a 64-bit program.

2. If your startup project, the main program (compiled as an exe file) is compiled under the x86 platform, and a project (or dynamic link library) it depends on is compiled by the x64 platform, it will An error such as "Failed to load file or assembly ... or one of its dependencies. Attempt to load a program with an incorrect format." This is because 32-bit programs cannot load 64-bit dlls, nor can they call classes, methods, and objects.
Conversely, what if the main program is compiled from the x64 platform and the dll is x86? answer. . Not good!
Speaking of which, basically one thing can be determined: as long as the generation platform of the dll and the main program are consistent .
Then the question is coming! What if the main program is compiled by Any CPU, and the dll is compiled by x86 or x64 platform, or the main program is compiled by x86 or x64 platform, and the dll is compiled by Any CPU? The correct answer is that both are feasible under "special circumstances". Why is it a "special case"? Because the first point is also mentioned, Any CPU depends on the operating system, and as mentioned in the second point, as long as the dll and the main program generation platform are the same, it is also feasible. Therefore, it can be seen from the above that if the main program is compiled under the Any CPU platform, the platform for compiling the dll must be consistent with the operating system for compiling the main program. If the main program is compiled under 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 is this? Please see the third point.

3. Although the program compiled by Any CPU depends on the operating system, the dll compiled by Any CPU depends on the main program that calls it. That is, if the main program is 32-bit, the dll is also 32-bit. If the main program is 64-bit, then the dll is 64-bit. Therefore, the dll is generally compiled using the Any CPU platform, and the main program (exe) is generally compiled using the x86 platform.

Summary: After understanding the difference between them, we know how to choose when we package the program. Generally speaking, when it is unclear what type of operating system the customer's computer is, or both, the main program is compiled on the x86 platform, and the dll is compiled on the Any CPU platform . If it is clear that it is a 64-bit operating system, then all can be compiled on the x64 platform.

Guess you like

Origin www.cnblogs.com/MCSFX/p/12670888.html