首页 > 解决方案 > 在 Windows 中临时删除环境 PATH 的一个变量

问题描述

我用 CMake 构建我的项目。

我想生成“MinGW Makefiles”,但 CMake 向我抛出了这个错误:

CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeMinGWFindMake.cmake:12 (message):
  sh.exe was found in your PATH, here:

  C:/Program Files/Git/usr/bin/sh.exe

  For MinGW make to work correctly sh.exe must NOT be in your path.

  Run cmake from a shell that does not have sh.exe in your PATH.

  If you want to use a UNIX shell, then use MSYS Makefiles.

Call Stack (most recent call first):
  CMakeLists.txt:3 (project)


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

似乎只有这个需要删除:

C:\Program Files\Git\cmd

在我的环境变量Path中。

所以我想知道如何在 Windows CLI 中做到这一点。

标签: windowscmakepathenvironment-variablesmingw

解决方案


在运行之前尝试在命令行环境中运行它cmake

set PATH=%PATH:C:\Program Files\Git\usr\bin;=%

C:\Program Files\Git\usr\bin;这将从您的PATH字符串变量中删除特定路径 ( ),并PATH使用字符串替换重新分配。


推荐阅读