1

How do I know if the program I am writing in C++ will run properly in a 32-bit OS or not?
(without manually testing in one)

I am using Visual Studio and compiling in a 64-bit machine. Will that stop the program from working in other machines?

And what about the processor and Windows version? Will the binary be compatible with most Windows versions and processors, if the program just does a few simple things such as web requests and calculations, with a simple user interface?

My program doesn't have to be 64-bit. I would just like to create one binary that runs in most computers, like those I download every day on the Internet. How could I do that?

Nuno
  • 3,082
  • 5
  • 38
  • 58
  • 2
    Are you asking whether the binary will run on 32-bit Windows, or whether the source code can be recompiled for 32-bit Windows and be expected to work? – NPE Jan 14 '14 at 20:50
  • I am asking if the binary will run on 32-bit. I'll edit my question. Thanks for the comment. – Nuno Jan 14 '14 at 20:51
  • 1
    @NunoPeralta: No. The compiler generates machine instructions. Those are obviously platform dependent. You know is your program is x86 compatible because that is (or is not) the architecture you targeted when you built it. – Ed S. Jan 14 '14 at 20:53
  • Thank you @EdS.. So if I build it as 32-bit, will it most likely work in most computers? – Nuno Jan 14 '14 at 20:58
  • You also need to consider the architecture, for example if you build your code for Intel Haswell with AVX2 but want it to run on the 95% of computers that don't have AVX2 instructions. I feel this question is too broad because it is asking for understanding of a lot of concepts in software distribution. – Mikhail Jan 14 '14 at 21:01
  • Well, I'm not sure if it is that broad. I just wonder how all those companies just deploy one EXE file to download and it works in most computers. Say Skype, Pidgin, etc... I don't download my machine-specific EXE, I download the only one that they provide. How do they do that? Thank you for your answer. – Nuno Jan 14 '14 at 21:10

3 Answers3

4

If you are building your code specifically for 64-bit Windows, you can't expect the binary to work on 32-bit Windows. That will require a separate build.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • Thank you. But, does that mean I have to get a 32-bit machine and compile my code there, or can I do that in the same machine? My program doesn't have to be 64-bit. I would just like to create one binary that runs in most computers, like those I download every day on the Internet. How could I do that? – Nuno Jan 14 '14 at 20:56
  • 1
    Just create a 32 bit application on 64 bit windows if your application does not require 64 bit. – drescherjm Jan 14 '14 at 20:59
  • @NunoPeralta: 64 bit Windows machines can compile and run 32 bit code. 32 bit Windows machines can compile 64 bit code, but can not run it. – Jonathan Potter Jan 14 '14 at 21:35
2

An executable compiled and linked for 64-bit will typically also require 64-bit libraries.

Use tools like the Dependency Walker to find out, if a given executable is refering to 32- or 64-bit libraries.

In Visual Studio, the "target platform" decides which CPU architecture you are targeting. It is perfectly feasible to create 64-bit executables on a 32-bit system, but you can't actually run them on such a machine.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54
0

You can do what's called cross-compiling i.e compiling on one machine for another. How to compile a 32-bit binary on a 64-bit linux machine with gcc/cmake This is what you're after if I read you correctly. There should be a Windows equivalent.

Community
  • 1
  • 1
JMercer
  • 352
  • 2
  • 9