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

我怕爱的太早我们不能终老 提交于 2019-12-05 11:25:37

问题


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?


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




回答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



回答3:


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

add_compile_options(-m64)


来源:https://stackoverflow.com/questions/11078915/how-to-compile-a-c-program-as-64-bit-on-64-bit-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!