I am developing a C app using Code::Blocks, and need to target multiple platforms (32 bit, 64 bit). My development box is 64 bit, so I tried to check the i386 (-march=i386) option for the compiler in the project settings. Now when I compile I get:
mainc:1: error: CPU you selected does not support x86-64 instruction set
-
I don’t understand this message! By specifying i386 shouldn’t it be just generating x86 instructions (not -64)? Beside, my CPU is X86-64 so why say my cpu doesn’t support this?
-
Am I doing this the wrong way? Is there a RIGHT way to target different architectures?
You must distinguish several things here:
-marchswitch). This decides what processor generation is assumed, which determines what instructions can be used in generating code. Not every combination of platform and architecture is valid (this is your very problem: assuming a 25 year old 386 processor means that it cannot possibly run in AMD64 mode).-mssefamily which further enable/disable instructions.You did not specify “Windows” or “Linux” or anything else, so it is hard to give an exact answer to what your problem is, but let’s assume you might be using for example MingW-w64. This compiler lets you create both 32 and 64 bit code, depending on what you tell it to do. Obviously, if you tell it to generate code in 64 mode (the default!), then i386 is not a good choice. If you give it
-m32as a commandline option, it will generate 32bit code, and it will work.It may help finding a more concrete answer if you tell exactly what compiler you use. Code::Blocks comes (optionally) with the TDM 4.5.1 build on Windows, for example, but uses whatever is there under other operating systems.