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

时间:2022-02-12 12:02:59

Perhaps a very trivial question:

也许是一个非常微不足道的问题:

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

我需要将程序编译为64位(编写早期的makefile以将其编译为32位)。

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?

我看到在每个文件编译的命令行参数中出现选项-m32。所以,我修改了makefile以摆脱OPTFLAG中的-m32,但是当程序编译时,我仍然看到-m32显示出来并且二进制文件仍然是32位。这个m32也来自其他地方吗?

2 个解决方案

#1


15  

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

-m32只能来自makefile中的某个地方,你必须跟踪它(使用递归grep)并删除它。

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

当我能够强制-m64时,我得到“你选择的CPU不支持x86-64指令集”。任何线索? uname -a给出了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.

该错误意味着makefile中有一个像-march = i686这样的选项,对于64位编译无效,请尝试删除它。

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.

如果你不能删除它(更加努力!)然后在命令行上添加-march = x86-64将指定通用的64位CPU类型。

#2


4  

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

如果您尝试构建的软件是基于autotools的,那么这应该可以解决问题:

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

Or, for just a plain Makefile:

或者,对于一个普通的Makefile:

env CFLAGS=-m64 CXXFLAGS=-m64 LDFLAGS=-m64 make

#1


15  

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

-m32只能来自makefile中的某个地方,你必须跟踪它(使用递归grep)并删除它。

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

当我能够强制-m64时,我得到“你选择的CPU不支持x86-64指令集”。任何线索? uname -a给出了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.

该错误意味着makefile中有一个像-march = i686这样的选项,对于64位编译无效,请尝试删除它。

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.

如果你不能删除它(更加努力!)然后在命令行上添加-march = x86-64将指定通用的64位CPU类型。

#2


4  

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

如果您尝试构建的软件是基于autotools的,那么这应该可以解决问题:

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

Or, for just a plain Makefile:

或者,对于一个普通的Makefile:

env CFLAGS=-m64 CXXFLAGS=-m64 LDFLAGS=-m64 make