21

Perhaps a very trivial question:

I need to compile a program as 64-bit (earlier makefile written to compile it as 32-bit).

I saw the option -m32 appearing in command line parameters with each file compilation. So, I modified the makefile to get rid of -m32 in OPTFLAG, but again when the program compiles, I still see -m32 showing up and binaries are still 32-bit. Does this m32 come from somewhere else as well?

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
xyz
  • 8,607
  • 16
  • 66
  • 90
  • What are you trying to compile? Perhaps you can reconfigure it with proper flags if it uses autotools instead of tweaking Makefile. If it is not your own software, you'd be better off asking corresponding community on how to properly build their software. Just from gcc point of view you need its proper version and `-m64` http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options . – mlt Jun 18 '12 at 08:03
  • make doesn't predefine -m32, nor does any other system component (unless there are any relevant distro-specific modifications, but there usually aren't), if that's what you're asking. –  Jun 18 '12 at 08:07
  • @mlt -m64 isn't necessary; -m64 is the default for a 64-bit compiler. –  Jun 18 '12 at 08:07
  • When I am able to force -m64, I get "CPU you selected does not support x86-64 instruction set".Any clues?. uname -a gives x86_64. – xyz Jun 18 '12 at 08:15
  • Please provide output of `gcc -v`. – Andrejs Cainikovs Jun 18 '12 at 08:17
  • 4
    the "CPU you selected" message means there is an option like `-march=i686` in the makefiles, which is not valid for 64-bit compilation, try removing that too, or adding `-march=generic` after it on the command line – Jonathan Wakely Jun 18 '12 at 08:18
  • True. I think Jonathans comment can be moved into answer. – Andrejs Cainikovs Jun 18 '12 at 08:24
  • @jonathan : It was -march=pentium3. Now It says : "error: bad value (generic) for -march= switch" – xyz Jun 18 '12 at 09:00
  • 1
    Oops, sorry, `-mtune=generic` is valid but not `-march=generic`. Suggestions moved to a new answer. – Jonathan Wakely Jun 18 '12 at 09:17

3 Answers3

24

-m32 can only be coming from somewhere in your makefiles, you'll have to track it down (use a recursive grep) and remove it.

When I am able to force -m64, I get "CPU you selected does not support x86-64 instruction set".Any clues?. uname -a gives x86_64

That error means there is an option like -march=i686 in the makefiles, which is not valid for 64-bit compilation, try removing that too.

If you can't remove it (try harder!) then adding -march=x86-64 after it on the command line will specify a generic 64-bit CPU type.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
9

If the software you are trying to build is autotools-based, this should do the trick:

./configure "CFLAGS=-m64" "CXXFLAGS=-m64" "LDFLAGS=-m64" && make

Or, for just a plain Makefile:

env CFLAGS=-m64 CXXFLAGS=-m64 LDFLAGS=-m64 make
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
  • As I mentioned in a comment already, `-m64` is the default for a 64-bit configured gcc. If you need to specify `-m64`, you're doing something wrong. If the package thinks it needs to add `-m32`, it's probably doing more than just that, and you're not dealing with the rest it does. –  Jun 18 '12 at 08:27
1

If you are using CMake, you can add m64 compile options by this:

add_compile_options(-m64)
Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Jayhello
  • 5,931
  • 3
  • 49
  • 56