How to make my C ++ programs multi-architecture (32 and 64 bits)?

7

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

    
asked by anonymous 22.07.2016 / 18:26

2 answers

6

Standard C ++ only generates native code for the architecture where it will run, so it has no way to run in a different architecture. The only way is to compile into the appropriate 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 with Windows and some Linux distributions. The opposite is not technically feasible even if someone wanted to do it.

Only 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 no one bothered to do this by not making much sense. Even .NET's C ++ / CLI does not allow this.

    
22.07.2016 / 19:56
4

The binaries will be different, so you can not take advantage of the exact same build.

You can force recompilation for both architectures at the same time, but it is generally not advisable to do this since you will waste more time compiling the wrong architecture during development and can make a script that generates the final version for both architectures in the end ...

    
22.07.2016 / 18:31