Gcc.exe 未安装错误不允许我安装 sqlx-cli

Gcc.exe not installed error not letting me install sqlx-cli

所以当我 运行 cargo install sqlx-cli 我得到这个错误时,我可以 运行 rust 代码,我检查了 windows SDK 和 C++ 框。我不知道,所以我该怎么做才能解决这个问题?我正在使用 windows 11

error: failed to run custom build command for `wepoll-ffi v0.1.2`

Caused by:
  process didn't exit successfully: `C:\Users\ali07\AppData\Local\Temp\cargo-installitFylM\release\build\wepoll-ffi-cc6f1ac54f6b60ea\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("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "gcc.exe" "-O0" "-ffunction-sections" "-fdata-sections" "-m64" "-Wall" "-Wextra" "-DNULL_OVERLAPPED_WAKEUPS_PATCH" "-o" "C:\Users\ali07\AppData\Local\Temp\cargo-installitFylM\release\build\wepoll-ffi-74b6f87d03081710\out\vendor/wepoll/wepoll.o" "-c" "vendor/wepoll/wepoll.c"

  --- stderr


  error occurred: Failed to find tool. Is `gcc.exe` installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)


warning: build failed, waiting for other jobs to finish...
error: failed to compile `sqlx-cli v0.5.9`, intermediate artifacts can be found at `C:\Users\ali07\AppData\Local\Temp\cargo-installitFylM`

Caused by:
  build failed

TARGET = Some("x86_64-pc-windows-gnu") 表示 cargo 正在尝试使用 gnu 工具链 (gcc) 构建您的项目。但是,如果您只安装了 msvc (visual studio) c++ 编译器,那么您将没有 gcc.

有两种解决方案:

A:最简单:告诉 cargo 使用 msvc

添加 --target 标志以改用 msvc:

cargo install sqlx-cli --target x86_64-pc-windows-msvc

B:安装gcc

这取决于您的开发环境。如果您使用的是 cygwin,那么您必须重新运行 cygwin 安装程序并确保在安装过程中安装 gcc。参见:https://superuser.com/questions/304541/how-to-install-new-packages-on-cygwin