How do I make my C++ programs multi-architecture (32 and 64 bit)?

Asked

Viewed 616 times

7

Developing a native C++ application using Devcpp and the Mingw compiler, when running the application on another machine I noticed an error regarding the architecture, because my program only runs in 64-bits, how can I leave it multi-architecture? That is, make it run in both 64-bit and 32-bit (without making a build for each of the architectures)

2 answers

7


Standard C++ only generates native code for the architecture it runs on, so there’s no way to run on different architecture. The only way is to compile for proper architecture.

Of course a 32-bit application could run on a 64-bit operating system if it has some compatibility layer. This is the case of Windows and some Linux distributions. The opposite is not technically feasible even if someone wanted to do it, except for a complex emulation and the result will be horrible.

Just compiling for another architecture may not be enough. The code needs to be well written to work well on both, the problem may be there.

Technically it would be possible to have a feature like C# (non-native code), but nobody bothered to do it because it didn’t make much sense.

4

The binaries will be different, so you can’t take advantage of the same build exactly.

It is possible to force the recompilation for both architectures at the same time, but it is generally not recommended to do this since you will spend more time compiling the wrong architecture during development and can make a script that manages the final version for the two architectures at the end...

  • This application I am developing is divided into client and server, the client is made in C#. NET and the server in native C++ . In the case of the client part, in Visual Studio there is the Any CPU option, so I thought it might be possible to leave the multi-architecture c++ application.

  • 1

    In case I compile for 32 bits, theoretically a 64 bit machine could also run it, right?

  • 1

    It is possible yes. The 64bit architecture is an extension of the 32bit. However, if you are integrating with other software that in one machine is 32 bits and in the other is 64 bits, the memory accesses can be compromised.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.