Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling for both x86 and x64

Is it possible to set up the compiler in such a way so it compiles the executable/DLL for both x86 and x64? I mean, one file suitable for both platforms.

I only know of a way to choose the platforms separately, but I want both.

Is it possible?

like image 794
Pateman Avatar asked Oct 07 '11 15:10

Pateman


People also ask

Can x86 programs run on x64?

WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows. This allows for 32-bit (x86) Windows applications to run seamlessly in 64-bit (x64) Windows, as well as for 32-bit (x86) and 32-bit (ARM) Windows applications to run seamlessly in 64-bit (ARM64) Windows.

Should I build for x86 or x64?

Since x86 apps run on both x64 and x86 systems, the most compatible choice is to build x86. If you MUST build a 64 bit solution, you'll need to target x64 and use our x64 dlls.

Why is x86-32 bit and x64 64 bit?

Probably because the x86 line became synonymous with 32 bit processors for quite some time, while x64 was specifically a designation for 64 bit as applications and operating systems were transitioned over, and now there are software applications that require the 64 bit designation in order to run (like some VM software ...

Is 86 and 64 bit same?

x86 refers to a 32-bit CPU and operating system while x64 refers to a 64-bit CPU and operating system. Does having more amount of bits in each operating system have any benefits? Of course! This is one of the main reasons the number of bits keeps increasing over the years from 16-bits to 64-bits currently.


1 Answers

x86 executable is fully supported on x64 host. E.g. any EXE you compile in 32-bit mode will run without any problems on 32-bit and 64-bit host. If you don't know why you need 64-bit executable, you probably don't, so 32-bit executable alone will suffice.

However, with DLLs it is a different matter. The DLL's architecture (32-bit or 64-bit) must match the executable where the DLL is going to be used. E.g. if you're writing an Explorer extension for x64 Windows, explorer.exe is going to be 64-bit, so your DLL must also be 64-bit, otherwise it cannot be loaded.

There is no way to combine two different architectures into one DLL or EXE on Windows. So you're going to need two DLLs if you need to support both 32-bit and 64-bit hosts.

like image 80
haimg Avatar answered Sep 22 '22 07:09

haimg