You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows MinGW环境cargo编译Rust项目失败报64位模式不支持错误

问题描述

在Windows系统上使用MinGW搭建Rust开发环境时,项目无法编译,尝试更换项目框架未解决问题,初步怀疑为cargo或Rust相关配置不正确导致,可能需要配置CC环境变量或修改其他相关环境变量。
核心报错为cc1.exe提示未编译支持64位模式,导致minimp3-sys、bzip2-sys等依赖crate构建失败。

完整报错输出
C:\Users\user0\Desktop\app>cargo run 
   Compiling minimp3-sys v0.3.2     
   Compiling bzip2-sys v0.1.11+1.0.8
   Compiling miniz_oxide v0.4.4
   Compiling quote v1.0.19
The following warnings were emitted during compilation:

warning: cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

error: failed to run custom build command for `minimp3-sys v0.3.2`

Caused by:
  process didn't exit successfully: `C:\Users\user0\Desktop\app\target\debug\build\minimp3-sys-6587a736db4ed872\build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("x86_64-pc-windows-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-gnu")
  CC_x86_64-pc-windows-gnu = None
  CC_x86_64_pc_windows_gnu = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-pc-windows-gnu = None
  CFLAGS_x86_64_pc_windows_gnu = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "minimp3/" "-Wall" "-Wextra" "-DMINIMP3_IMPLEMENTATION" "-o" "C:\\Users\\user0\\Desktop\\app\\target\\debug\\build\\minimp3-sys-2cb72c58d710f12a\\out\\minimp3.o" "-c" "minimp3.c"
  cargo:warning=cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
  exit code: 1

  --- stderr


  error occurred: Command "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "minimp3/" "-Wall" "-Wextra" "-DMINIMP3_IMPLEMENTATION" "-o" "C:\\Users\\user0\\Desktop\\app\\target\\debug\\build\\minimp3-sys-2cb72c58d710f12a\\out\\minimp3.o" "-c" "minimp3.c" with args "gcc.exe" did not execute successfully (status code exit code: 1).


warning: build failed, waiting for other jobs to finish...
The following warnings were emitted during compilation:

warning: cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

error: failed to run custom build command for `bzip2-sys v0.1.11+1.0.8`

Caused by:
  process didn't exit successfully: `C:\Users\user0\Desktop\app\target\debug\build\bzip2-sys-faace576cdcf109f\build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("x86_64-pc-windows-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-gnu")
  CC_x86_64-pc-windows-gnu = None
  CC_x86_64_pc_windows_gnu = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-pc-windows-gnu = None
  CFLAGS_x86_64_pc_windows_gnu = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "bzip2-1.0.8" "-D_WIN32" "-DBZ_EXPORT" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "C:\\Users\\user0\\Desktop\\app\\target\\debug\\build\\bzip2-sys-f1b348dca76e3f18\\out\\lib\\bzip2-1.0.8/blocksort.o" "-c" 
"bzip2-1.0.8/blocksort.c"
  cargo:warning=cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
  exit code: 1

  --- stderr


  error occurred: Command "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "bzip2-1.0.8" "-D_WIN32" "-DBZ_EXPORT" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "C:\\Users\\user0\\Desktop\\app\\target\\debug\\build\\bzip2-sys-f1b348dca76e3f18\\out\\lib\\bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" with args "gcc.exe" did not execute successfully (status code exit code: 1).
项目配置(Cargo.toml)
[package]
name = "app"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ggez = "*"
参考截图
问题根因

当前安装的是仅支持32位编译的旧版MinGW,而Rust使用的x86_64-pc-windows-gnu工具链为64位版本,编译带C源码的依赖时会自动传入-m64参数要求生成64位目标文件,32位gcc不支持该编译参数,直接报错退出。

解决方案

优先推荐替换为64位编译工具链,步骤如下:

  • 卸载当前已安装的32位旧版MinGW,下载安装MinGW-w64(旧版MinGW早已停止维护,无官方64位支持),安装时架构选择x86_64,线程模型选posix,异常处理模型选seh即可。
  • 编辑系统环境变量PATH,删除原有32位MinGW的bin目录路径,添加新安装的MinGW-w64对应的bin目录路径。
  • 打开新的命令提示符窗口,执行gcc -v验证配置,输出内容中Target字段为x86_64-w64-mingw32即代表64位gcc配置生效。
  • 回到项目目录执行cargo clean清除历史编译缓存,再执行cargo run即可正常编译运行。

如果暂时不想替换MinGW,也可以安装32位Rust GNU工具链适配,执行rustup target add i686-pc-windows-gnu后,通过cargo run --target i686-pc-windows-gnu命令编译,该方式生成的是32位程序,仅作为临时方案使用。


内容的提问来源于stack exchange,提问作者user13715072

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 09:57:16