CMake在Windows上无法创建MakeFile

8
当我尝试运行cmake时,它生成了很多文件但没有创建Makefile。
CMakeLists.txt
PROJECT(main)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16) 
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(main ${DIR_SRCS})

main.c

int main()
{
    return 0;
}

在 cmd 中运行 cmake 后,它给出了以下内容。
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

生成文件后,一些文件会被生成。
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

在其中找不到MakeFile。可能是一些明显的错误,但我就是找不到它。我已经卡在这里几个小时了,希望有人能提供帮助,谢谢!

1个回答

15
在类Unix平台上,运行cmake然后运行make默认创建Makefiles。但在Windows上不是这样的。
在Windows上,默认情况下,CMake会生成一个MSVC解决方案。请检查您的构建目录中是否有.sln文件。
如果您确实想在Windows上使用Makefiles,请将-G "Unix Makefiles"添加到cmake命令行中。
如果您想使用MSVC作为编译器但在命令行上工作,则另一种选择是-G "NMake Makefiles",然后再调用make
在尝试构建新生成器目标之前,请确保删除您的构建目录。CMake对此可能会很敏感。
请检查cmake --help以获取可用选项列表。(特别是生成器目标是特定于平台的。)

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