1

I know there are already a few answers to this question but I can't seem to understand why I keep getting this error.

So here's the explanation: I have 64 bits machine in which I've installed Windows 7 x64. I am compiling my Code under GCC (CodeBlocks) on Windows without any problem AT ALL. Then I decided that my application has to be portable, and I decided to compile it under GCC on Linux. In my other 32bit machine the code is compiling without any problem. However, on my 64 bit machine, I decided to install Ubuntu as Wubi. Of course I have installed Wubi x64 version as well.

I installed Ubuntu successfully under Wubi, I installed all necessary stuff, but when I try to compile my project, I get in the very first line the error 'cpu you selected does not support x86-64 instruction set'. Ok, this sounds completely non sense to me, taking into account that I've installed Wubi x64, on Windows 7 x64, on a 64bits machine. So why the hell am I getting an error saying that my CPU does not support x86-64 instruction set?

Could it be JUST because I have installed WUBI instead of installing Ubuntu on root in a normal way? I really can't seem to get this thing.

Thank you very much

EDIT: Ok, somewhere in Codeblocks I found the option that was checked for "Pentium M" architectures. I've unchecked it and now I get several erros such as:

error: cast from void* to int loses precision.

For which reason should this happen ONLY on Linux and not on Windows?

filipehd
  • 900
  • 3
  • 13
  • 30
  • 1
    This answer hasn't helped? http://stackoverflow.com/a/11079910/777186 – jogojapan Oct 18 '12 at 09:32
  • It may be useful to actually link to the other questions you mention, and perhaps explain which of the suggested approaches mentioned there you have tried. – jogojapan Oct 18 '12 at 09:33
  • 3
    This is not about your CPU, it's about _the CPU you are compiling your application for_. – themel Oct 18 '12 at 09:45
  • That you get different errors/warnings on different compilers is not that surprising. One might be better at spotting a particular problem, or you use slightly different options on the systems. – Bo Persson Oct 18 '12 at 09:55
  • What command is emitting that error message? – PlasmaHH Oct 18 '12 at 09:57
  • Also see ["CPU you selected does not support x86-64 instruction set" error on Cygwin-x64](http://stackoverflow.com/a/35533259/608639). It tells you how to build OpenSSL 1.0.1 and 1.0.2 for Cygwin-x64. – jww Feb 21 '16 at 07:16

1 Answers1

9

Based on this comment:

EDIT: Ok, somewhere in Codeblocks I found the option that was checked for "Pentium M" architectures. I've unchecked it and now I get several erros such as:

This was the reason for the compilation problem - "Pentium M" is a 32bit architecture. gcc under CodeBlocks will produce 32bit code on Windows by default

The error:

error: cast from void* to int loses precision.

Is caused because the model for 64bit on linux x64 is LP64, where sizeof(long) == sizeof(pointer) == 64bits, and sizeof(int) == 32bits and you're trying to shove a pointer(void *)(64bits) into an int(32bits), which causes pointer information to be lost.

With a compilation error like that, it's most likely that the code is not 64bit clean.

For which reason should this happen ONLY on Linux and not on Windows?

Linux on x64 defaults to producing 64bit applications, you would need to add -m32 to the build options for the program to make it produce 32bit code (there is probably a CodeBlocks target option to do this)

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • Clear and Specific answer. Thank you very much! – filipehd Oct 22 '12 at 13:07
  • anyway, does anyone know how to install the 32bit development kit for GCC on 64bit ubuntu? – filipehd Oct 24 '12 at 06:08
  • From our friends over in unix.stackexchange.com - http://unix.stackexchange.com/questions/12801/building-32-bit-on-a-64-bit-system – Anya Shenanigans Oct 24 '12 at 07:11
  • From the drop down menus, go to PROJECT->BUILD OPTIONS->COMPILER SETTINGS and under the GENERAL section, you should see options (near the bottom of that section) for -m32 and -m64. It's a good idea to set it. Never assume it's the default, especially when compiling for cross platform. Note: if you do not see these options, you can add them yourself. Just right click on GENERAL and select NEW FLAG. You can add flags for both. Code::Blocks v16.01 has them though, at least on the Windows build. – Neil Roy Jun 12 '17 at 01:45