Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a C++ program as 64-bit on 64-bit machine?

Tags:

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?

like image 440
xyz Avatar asked Jun 18 '12 07:06

xyz


2 Answers

-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.

like image 146
Jonathan Wakely Avatar answered Sep 21 '22 11:09

Jonathan Wakely


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
like image 35
Andrejs Cainikovs Avatar answered Sep 17 '22 11:09

Andrejs Cainikovs