How to compile a C++ program as 64-bit on 64-bit machine?
Solution 1
-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.
Solution 2
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
Solution 3
If you are using cmake, you can add m64 compile options by this:
add_compile_options(-m64)
xyz
Updated on July 17, 2022Comments
-
xyz almost 2 years
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?
-
Admin almost 12 yearsAs 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.