g++ 编译选项 -m

gcc提供了编译选项可以为指定架构生成汇编代码,

These ‘-m’ switches are supported in addition to the above on x86-64 processors in 64-bit environments.
-m32    32位版:加上 -m32 参数,生成32位的汇编代码;
-m64     g++ -m64  加上 -m64 参数,生成64位的汇编代码;
-mx32
-m16

由于64位机器的寄存器比32位机器多很多,所以GCC编译器会尽量使用寄存器来传递参数,而不是32位机器下的压栈。

-miamcu Generate code for a 16-bit, 32-bit or 64-bit environment.

The ‘-m32’ option
sets int, long, and pointer types to 32 bits, and generates code that runs on any i386 system.
-m32选项将int,long和指针设置为32位,编译出来的是32位程序,既可在32位操作系统运行,又可在64位操作系统运行。
$ g++ size.cpp -O3 -m32 -o size
$ readelf -h ./size
Class:                             ELF32
 Machine:                           Intel 80386

The ‘-m64’ option 
sets int to 32 bits and long and pointer types to 64 bits, and generates code for the x86-64 architecture. For Darwin only the ‘-m64’ option also turns off the ‘-fno-pic’ and ‘-mdynamic-no-pic’ options.
-m64选项将int设置为32位和long,指针设置为64位,并为AMD的x86-64体系结构生成代码。
$ g++ size.cpp -O3 -o size
$ readelf -h ./size
 Class:                             ELF64
 Machine:                           Advanced Micro Devices X86-64

The ‘-mx32’ option
sets int, long, and pointer types to 32 bits, and generates code for the x86-64 architecture.
-mx32选项将int,long和指针设置为32位,并为AMD的x86-64体系结构生成代码。编译出的程序只能在x86-64上运行。
$ g++ size.cpp -O3 -mx32 -o size
$ readelf -h ./size
Class:                             ELF32
Machine:                           Advanced Micro Devices X86-64

The ‘-m16’ option is the same as ‘-m32’, except for that it outputs the code16gcc assembly directive at the beginning of the assembly output so
that the binary can run in 16-bit mode.

-m16,只有在32位的linux上才能使用,同样需要在编译内核时做设置,只有在32位内核中才有该选项,gcc同样也只有32位版本才支持。几乎没人使用,除了某些16位的嵌入式



 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值