cc1: error: unrecognized command line option "-m64" 需要添加上ARCH=arm

本文详细介绍了在使用Linux内核源码进行编译时遇到的命令行选项错误,并提供了相应的解决方案。通过修改命令行参数,成功解决了在编译过程中出现的错误,最终实现了模块的正确构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[root@localhost pwm2]# make
make -C  /work/cs/YL-9G45/linux-2.6.30  M=/work/rootfs/test/pwm2 modules
make[1]: Entering directory `/work/cs/YL-9G45/linux-2.6.30'
  CC [M]  /work/rootfs/test/pwm2/pwm.o
cc1: error: unrecognized command line option "-m64"
cc1: error: unrecognized command line option "-mno-red-zone"
cc1: error: unrecognized command line option "-mcmodel=kernel"
cc1: error: unrecognized command line option "-maccumulate-outgoing-args"
make[2]: *** [/work/rootfs/test/pwm2/pwm.o] 错误 1
make[1]: *** [_module_/work/rootfs/test/pwm2] 错误 2
make[1]: Leaving directory `/work/cs/YL-9G45/linux-2.6.30'
make: *** [all] 错误 2
[root@localhost pwm2]# export ARCH=arm
[root@localhost pwm2]# make
make -C  /work/cs/YL-9G45/linux-2.6.30  M=/work/rootfs/test/pwm2 modules
make[1]: Entering directory `/work/cs/YL-9G45/linux-2.6.30'
  CC [M]  /work/rootfs/test/pwm2/pwm.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /work/rootfs/test/pwm2/pwm.mod.o
  LD [M]  /work/rootfs/test/pwm2/pwm.ko
make[1]: Leaving directory `/work/cs/YL-9G45/linux-2.6.30'
[root@localhost pwm2]# 
root@4a39b502e13d:/nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface# make gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) make -C /nvmp_source_dir/sdk/soc/ssc30x/linux-5.10.117 M=/nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface modules make[1]: Entering directory '/nvmp_source_dir/sdk/soc/ssc30x/linux-5.10.117' make[2]: Entering directory '/nvmp_source_dir/sdk/soc/ssc30x/linux-5.10.117' CC [M] /nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface/tp_rc.o cc1: error: plugin support is disabled; configure with --enable-plugin cc1: error: plugin support is disabled; configure with --enable-plugin cc1: error: plugin support is disabled; configure with --enable-plugin cc1: error: unrecognized command line option '-Wno-typedef-redefinition' [-Werror] cc1: all warnings being treated as errors scripts/Makefile.build:273: recipe for target '/nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface/tp_rc.o' failed make[3]: *** [/nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface/tp_rc.o] Error 1 Makefile:2030: recipe for target '/nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface' failed make[2]: *** [/nvmp_source_dir/sdk/soc/ssc30x/mpp/ssc308/interface] Error 2 make[2]: Leaving directory '/nvmp_source_dir/sdk/soc/ssc30x/linux-5.10.117' makefile:22: recipe for target 'modules' failed make[1]: *** [modules] Error 2 make[1]: Leaving directory '/nvmp_source_dir/sdk/soc/ssc30x/linux-5.10.117' Makefile:27: recipe for target 'all' failed make: *** [all] Error 2 gcc -v显示--enable-plugin,为什么还会报错呢?
03-13
<think>好的,我现在需要解决用户提到的C++编译时出现的“unrecognized command-line option '-m64'”错误。首先,我需要理解这个错误的原因。根据用户提供的引用资料,特别是引用[2]提到的,这个错误通常发生在交叉编译环境中,特别是当编译器是32位系统的时候,而编译选项里使用了-m64,导致编译器无法识别这个选项。 接下来,我应该回顾错误信息本身。-m64选项通常是用来指定生成64位代码的。但如果编译器本身是32位的,或者目标平台不支持该选项,就会报错。比如在OpenWrt这样的嵌入式系统中,很多工具链是32位的,这时候使用-m64就会出现问题。 用户的问题是关于C++编译的,所以可能需要检查他们的编译环境和工具链。可能的解决方案包括: 1. 检查编译器是否支持-m64选项。可以通过运行g++ -v --help或者查看编译器文档来确认。 2. 如果编译器不支持-m64,可能需要移除该选项。比如在Makefile或CMakeLists.txt中找到使用-m64的地方并删除。 3. 如果确实需要生成64位代码,可能需要更换为支持64位的交叉编译工具链。 4. 如果是交叉编译,确保正确设置了目标平台的相关参数,比如使用--host指定架构,避免自动添加不兼容的选项。 5. 参考引用[2]中提到的,检查是否因为未正确设置os/compile参数导致默认添加-m64,这时候可能需要显式设置正确的参数来覆盖默认值。 另外,需要确保整个项目配置中没有隐式添加-m64的地方。比如某些构建系统可能会根据平台自动添加选项,这时候需要手动调整配置。此外,如果项目依赖的第三方库或脚本中硬编码了-m64,也需要修改这些部分。 总结可能的解决步骤: - 确认编译器版本和支持的选项,移除不支持的-m64- 检查构建系统的配置,确保没有自动添加该选项。 - 更换合适的工具链或调整目标平台设置。 - 参考类似问题的解决方法,如引用[2]中提到的处理方式。 最后,需要验证解决方案是否有效。用户可以在修改后重新编译,观察是否仍然出现错误,并确认生成的二进制文件是否符合预期架构(32位或64位)。</think>要解决C++编译时出现的`unrecognized command-line option '-m64'`错误,需从编译环境和选项设置入手。以下是逐步解决方案: --- ### **步骤1:理解错误原因** `-m64`是GCC/G++编译器用于生成**64位代码**的选项。当编译器不支持该选项(如32位编译器)或目标平台不兼容时,会触发此错误[^2]。常见场景: - **交叉编译**时工具链为32位(如OpenWrt嵌入式系统) - 错误地在编译脚本中手动添加`-m64`选项 --- ### **步骤2:检查编译器兼容性** 通过命令查看编译器支持的选项: ```bash g++ -v --help | grep "\-m" ``` 若无`-m64`输出,说明当前编译器不支持生成64位代码。 --- ### **步骤3:移除或替换编译选项** - **直接移除`-m64`** 在Makefile、CMakeLists.txt或编译脚本中删除所有`-m64`参数。例如: ```makefile # 修改前 CFLAGS += -m64 -O2 # 修改后 CFLAGS += -O2 ``` - **动态判断平台** 在构建脚本中添加条件判断,仅当编译器支持时添加`-m64`: ```bash if g++ -m64 -dM -E - </dev/null >/dev/null 2>&1; then CFLAGS+=" -m64" fi ``` --- ### **步骤4:更换工具链(交叉编译场景)** 若需生成**64位目标代码**,需确保工具链支持: - **确认目标平台架构**(如`aarch64`对应64ARM- **使用正确的交叉编译器**(如`aarch64-linux-gnu-g++`代替`arm-linux-gnueabihf-g++`) - 在编译配置中显式指定目标平台(如CMake): ```bash cmake -DCMAKE_TOOLCHAIN_FILE=arm64_toolchain.cmake ``` --- ### **步骤5:修复构建系统配置** 某些构建系统(如Autotools)可能自动添加`-m64`。需通过配置参数禁用: ```bash ./configure --build=x86_64-linux-gnu --host=arm-linux-gnueabihf ``` 或针对OpenWrt等嵌入式系统,在`Makefile`中设置: ```makefile TARGET_CFLAGS := -march=armv7-a # 替换为实际支持的架构参数 ``` --- ### **验证解决方案** 重新编译后,检查输出文件是否为预期架构: ```bash file ./output_binary # 期望输出:ELF 32-bit LSB executable, ARM... ``` --- ### **总结** - **根本原因**:`-m64`与当前编译器或目标平台不兼容[^2] - **核心思路**:移除不兼容选项或更换支持64位的工具链 - **扩展建议**:在交叉编译时始终通过`--host`和`--build`参数明确目标平台 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值