在 Windows 上运行 CMake

Posted

技术标签:

【中文标题】在 Windows 上运行 CMake【英文标题】:Running CMake on Windows 【发布时间】:2011-05-05 07:50:33 【问题描述】:

我目前正在尝试让 CMake 在我的 Windows 7(64 位)系统上运行。我想编译 TagLib 以供以后与我正在开发的 Qt 应用程序一起使用。我想用 MinGW 编译它(不是 this other question 中的 Visual C++)。

我下载安装程序 (cmake-2.8.3-win32-x86.exe) 并安装它(我还选择将 CMake 添加到我的路径中)。然后我转到 CMakeLists.txt 文件所在的目录并运行cmake .。然后它给了我这个巨大的错误。

C:\Users\Joel\Downloads\taglib-1.6.3>cmake .
CMake Warning at CMakeLists.txt:1 (project):
  To use the NMake generator, cmake must be run from a shell that can use the
  compiler cl from the command line.  This environment does not contain
  INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
  work.


-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Warning at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:
28 (ENABLE_LANGUAGE):
  To use the NMake generator, cmake must be run from a shell that can use the
  compiler cl from the command line.  This environment does not contain
  INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
  work.
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
  CMakeLists.txt:1 (project)


CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found.   Please set CMAKE_RC_COM
PILER to a valid compiler path or name.
-- Check for CL compiler version
-- Check for CL compiler version - failed
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - yes
-- Using FREE VC TOOLS, NO DEBUG available
-- Check for working C compiler: cl
CMake Warning at CMakeLists.txt:2 (PROJECT):
  To use the NMake generator, cmake must be run from a shell that can use the
  compiler cl from the command line.  This environment does not contain
  INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
  work.


CMake Warning at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:
28 (ENABLE_LANGUAGE):
  To use the NMake generator, cmake must be run from a shell that can use the
  compiler cl from the command line.  This environment does not contain
  INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
  work.
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
  CMakeLists.txt:2 (PROJECT)


CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeRCInformation.cmake:22
(GET_FILENAME_COMPONENT):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:28 (ENABLE_LANG
UAGE)
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
  CMakeLists.txt:2 (PROJECT)


CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage
CMake Error: your C compiler: "cl" was not found.   Please set CMAKE_C_COMPILER to a valid compiler
path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: cl -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52
(MESSAGE):
  The C compiler "cl" is not able to compile a simple test program.

  It fails with the following output:





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:1 (project)


CMake Error: your C compiler: "cl" was not found.   Please set CMAKE_C_COMPILER to a valid compiler
path or name.
CMake Error: your CXX compiler: "cl" was not found.   Please set CMAKE_CXX_COMPILER to a valid compi
ler path or name.
-- Configuring incomplete, errors occurred!

C:\Users\Joel\Downloads\taglib-1.6.3>

考虑到它标榜自己是跨平台品牌,我有点惊讶于它开箱即用地失败了。

我尝试将 INCLUDE、LIB 和 LIBPATH(Windows 环境变量)全部设置到我的 MinGW 二进制文件目录 (C:\MinGW\bin),但它仍然给我同样的错误。我还尝试将 CMAKE_C_COMPILER 和 CMAKE_CXX_COMPILER 设置为 g++ (C:\MinGW\bin\g++) 的位置。

有人知道这里发生了什么吗?

解决方案:

根据 tibur 的建议,我运行 cmake GUI 来创建 make 文件。 然后我进入目录 taglib 目录并运行mingw32-make.exe 进行实际构建。

【问题讨论】:

【参考方案1】:

Windows 的默认生成器似乎设置为 NMAKE。尝试使用:

cmake -G "MinGW Makefiles"

或使用 GUI,并在提示输入生成器时选择 MinGW Makefiles。不要忘记清理您尝试运行 CMake 的目录,或删除 GUI 中的缓存。否则,它将使用 NMAKE 重试。

【讨论】:

下一步是运行mingw32-make.exe all 进行实际构建。 +1 我错过了mingw32-make.exe,并受到了一个神秘的 No sane CXX 编译器的欢迎。 Gnu Make for Windows 没有删减,需要 MinGW 版本。 如果您在 Bash shell(在 Windows 上),显然您必须使用“MSYS Makefiles”【参考方案2】:

在您的 Visual Studio 安装目录中有一个 vcvars32.bat。您可以在该批处理程序的末尾添加 call cmd.exe 并启动它。在该 shell 中,您可以使用 CMake 或 cmake-gui,并且 CMake 会知道 cl.exe。

【讨论】:

在vcvars32/64.bat中添加对cmd.exe的调用的代码是:@call "cmd.exe"【参考方案3】:

对我有用的命令是:

$ cmake -G "MSYS Makefiles" ..

我正在使用 MSYS2/Win10 编译 QT5 应用程序@64bit(使用 MINGW64 shell)

【讨论】:

【参考方案4】:

使用:cmake --build 在 cmake -G "MinGW Makefiles" 之后

【讨论】:

以上是关于在 Windows 上运行 CMake的主要内容,如果未能解决你的问题,请参考以下文章

odoo10.0可以在windows上运行吗

如何在Windows上配置并运行Nginx

如何在Windows上配置并运行Nginx

如何在Windows上配置并运行Nginx

如何在Windows上配置并运行Nginx

如何在windows上配置并运行Nginx