xyz
xyz

Reputation: 8917

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

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?

Upvotes: 22

Views: 110142

Answers (3)

Jayhello
Jayhello

Reputation: 6592

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

add_compile_options(-m64)

Upvotes: 1

Jonathan Wakely
Jonathan Wakely

Reputation: 171253

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

Upvotes: 25

Andrejs Cainikovs
Andrejs Cainikovs

Reputation: 28424

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

Upvotes: 9

Related Questions