在Windows上运行CMake

75

我目前正在尝试在我的Windows 7(64位)系统上运行CMake。 我想编译TagLib,以便日后在我正在开发的Qt应用程序中使用。 我想使用MinGW进行编译(而不是像这个问题中那样使用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进行实际构建。

4个回答

116

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

cmake -G "MinGW Makefiles"

或者使用图形用户界面,在提示选择生成器时选择MinGW Makefiles。不要忘记清理尝试运行CMake的目录,或在GUI中删除缓存,否则它会再次尝试使用NMAKE。


11
下一步是运行mingw32-make.exe all来进行实际的构建。 - David C
2
+1 我缺少 mingw32-make.exe,并且看到了一个晦涩的“无理性 CXX 编译器”错误提示。Windows 版本的 Gnu Make 不能胜任此任务,需要使用 MinGW 版本。 - Vorac
3
如果您正在 Bash shell(Windows 上),显然您需要使用“MSYS Makefiles”。 - gd1

14

在你的Visual Studio安装目录中有一个vcvars32.bat文件。你可以在该批处理程序的结尾处添加调用cmd.exe并启动它。从那个shell中,你可以使用CMake或cmake-gui,cl.exe将被CMake识别。


1
在vcvars32/64.bat中添加对cmd.exe的调用代码是:@call "cmd.exe" - NumesSanguis

0

适用于我的命令是:

$ cmake -G "MSYS Makefiles" ..

我正在使用MSYS2/Win10编译一个64位的QT5应用程序(使用MINGW64 shell)


0
使用:在执行 cmake -G "MinGW Makefiles" 后,运行 cmake --build 命令。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接