. NET-compiled target platform (anycpu,x86,x64)

Source: Internet
Author: User

Reprint: http://blog.sina.com.cn/s/blog_78b94aa301014i8r.html

Today, the code of the project receives feedback from the customer, requiring all EXE project target platforms to be designated as x86, and all DLL project target platforms are designated as ANYCPU.

Let's take a look at what this target platform does, and what's the difference between the options.

In VisualStudio, the following options are available in the compilation settings:

x86: Compiles the assembly to run by a compatible x86 32-bit common language runtime.

x64: Compiles the assembly to run by the 64-bit common language runtime on the computer that supports the AMD64 or EM64T instruction set.

ANYCPU: (The default value) compiles the assembly to run on any platform.

Itanium: Compiles the assembly to run by the 64-bit common language runtime on the Itanium processor-based computer.

The specific behavior is as follows:

On a 64-bit Windows operating system:

Assemblies compiled with x86 will be executed on the 32-bit CLR running under WOW64.

Assemblies compiled with x64 will be executed on the 64-bit CLR.

Executable files compiled with ANYCPU will be executed on the 64-bit CLR.

A DLL compiled with ANYCPU will execute on the same CLR as the process that loaded it.

On a 32-bit Windows operating system:

Assemblies compiled with x86 or ANYCPU will be executed on the 32-bit CLR.

Assemblies compiled with x64 cannot be run.

After figuring out these differences, it makes no sense to look back at what the customer is asking for.

The first thing to know is that the client wants the program to run in every system above WinXP (either 32-bit or 64-bit).

Therefore, it is not possible to choose x64,itanium for special processors.

Do you have any problems choosing the default mode of any CPU?

First look at any CPU and x86 executable (EXE) under 32-bit and 64-bit what is the difference,

Any CPU under 32 bits, EXE will be executed with 32 bit, and under 64 bits, EXE will be executed with 64 bit. And x86 's words are always executed with 32 bits.

Customers want to use the x86, that is, do not want 64-bit under the 64-bit way to execute EXE program. My analysis is due to the possible existence of a third-party 32-bit DLL in the system, once the 64-bit EXE is used, it will not be called when calling to a 32-bit DLL.

While the DLL, the customer would like to take the any CPU, I analyze the reason is that the actual operation of the DLL is affected by the exe that called it, so set to any CPU is possible. And if it's set to x86, it doesn't seem to be a problem, but it can't run in the 64-bit CLR, not too good.

Resources:

Http://msdn.microsoft.com/zh-cn/library/zekwfyz4 (vs.80). aspx

------------------------------

To add, you can use the CorFlags command provided in the. NET SDK to view the target platform of an assembly, or you can modify it so that you do not have to recompile. But why can't a 64-bit EXE call a 32-bit DLL?

. NET-compiled target platform (anycpu,x86,x64)

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.