1

I have a W7 x64 PC but I aware about compatibility when the final application will be installed in another PC.

Does automatically run on any Windows PC? What I should take in account to improve compatibility?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
E_Blue
  • 1,021
  • 1
  • 20
  • 45
  • 1
    A 64-bit version of Windows includes the WOW compatibility layer, so pretty much any 32-bit application runs fine. I do all of my development on 64-bit workstations, mainly targeting 32-bit clients. The only thing you *cannot* do is mix binaries—one 32-bit and one 64-bit, for example—so all of your libraries need to target the same architecture as your application. – Cody Gray - on strike Feb 02 '16 at 16:03
  • @CodyGray So when I compile in a x64 OS I get two binaries, one for x64 and one for x32? – E_Blue Feb 02 '16 at 16:38
  • 1
    No, you only get the binaries that you request the compiler to generate. Both platforms (x86 and x64) have cross-compilers that can generate binaries for the other platform. And obviously you can generate a binary for your current platform. .NET also has this "Any CPU" complication, which you can set to cause the JITer to generate code on-the-fly for the current architecture of the system. It's great for maximizing deployability of your application, but is a nightmare for apps that depend on third-party libraries. Remember that the bitness of all libraries must match the application. – Cody Gray - on strike Feb 03 '16 at 01:36

1 Answers1

3

Yes, you can compile x86, x64 or Any CPU applications. You can also run any of these on your x64 machine.

If you compile an x64 application, this can only be run on an x64 machine. That is the only restriction.

Note that if you are using an assembly that has been compiled for a specific architecture, your application needs to use the same architecture to avoid errors when running on another machine.

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • So I must use always set "Any CPU" when compiling to improve compatibility, What are the disadvantages? Why is not set as default? – E_Blue Feb 02 '16 at 16:36
  • use Any CPU if all the assemblies you are referencing are also set for Any CPU. – Matt Wilko Feb 02 '16 at 16:51
  • 1
    @E_Blue Any CPU is the default. The reason you would not use it is your program (or a library your program uses) must communicate with native (non .NET) code. Native code can not automatically switch between 64 bit mode and 32 bit mode. It can only do one or the other. 32 bit programs can run on 64 bit windows so often people only release a 32 bit version of their dll because it will work with both anyway. – Scott Chamberlain Feb 02 '16 at 17:03
  • @ScottChamberlain What about things like MySQL connector or a WebKit? – E_Blue Feb 04 '16 at 13:53
  • 1
    @E_Blue It depends on the library. MySQL's connector will work with both 32 bit or 64 bit, I have never used WebKit so I can't say. – Scott Chamberlain Feb 04 '16 at 14:32