CMake 无法在 Windows 上创建 MakeFile

王子铭*_*王子铭 5 c makefile cmake

当我尝试运行时cmake,它确实生成了一堆文件,但没有创建 MakeFile。

CMakeLists.txt

PROJECT(main)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16) 
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(main ${DIR_SRCS})
Run Code Online (Sandbox Code Playgroud)

主文件

int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

cmake在cmd中运行后,它给了我这个

E:\practiceFolder\cake>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The C compiler identification is MSVC 19.21.27702.2
-- The CXX compiler identification is MSVC 19.21.27702.2
-- Check for working C compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: E:/practiceFolder/cake
Run Code Online (Sandbox Code Playgroud)

之后生成一些文件

E:.
?  ALL_BUILD.vcxproj
?  ALL_BUILD.vcxproj.filters
?  CMakeCache.txt
?  CMakeLists.txt
?  cmake_install.cmake
?  main.c
?  main.sln
?  main.vcxproj
?  main.vcxproj.filters
?  ZERO_CHECK.vcxproj
?  ZERO_CHECK.vcxproj.filters
?
??CMakeFiles
    ?  cmake.check_cache
    ?  CMakeOutput.log
    ?  generate.stamp
    ?  generate.stamp.depend
    ?  generate.stamp.list
    ?  TargetDirectories.txt
    ?
    ??3.16.2
and some other files
Run Code Online (Sandbox Code Playgroud)

在其中找不到 MakeFile。这里可能有一些明显的错误,但我找不到它。我已经被困在这里几个小时了,任何帮助将不胜感激,谢谢!

Eya*_*lan 9

在类 Unix 平台中,默认运行cmake然后make创建 Makefile。在 Windows 上不是这种情况。

在 Windows 上,CMake 默认生成 MSVC 解决方案。检查.sln构建目录中的文件。

如果您确实需要 Windows 上的 Makefile,请添加-G "Unix Makefiles"到该cmake行。

如果你想使用 MSVC 作为编译器但在命令行上工作,另一个选项是-G "NMake Makefiles",然后调用make

在尝试构建新的生成器目标之前,请确保删除您的构建目录。CMake 可能对此很敏感。

检查cmake --help可用选项列表。(尤其是生成器目标是特定于平台的。)