在 Windows 上运行 CMake

我目前正在尝试让 CMake 在我的 Windows7(64位)系统上运行。我想编译 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来完成实际的构建。

117231 次浏览

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

cmake -G "MinGW Makefiles"

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

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

对我有效的命令是:

$ cmake -G "MSYS Makefiles" ..

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

用途: cmake —— build 在 cmake-G“ MinGW Makefile”之后