【问题标题】:CMake cannot create MakeFile on WindowsCMake 无法在 Windows 上创建 MakeFile
【发布时间】:2023-03-26 17:52:02
【问题描述】:

当我尝试运行 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。可能这里有一些明显的错误,但我就是找不到。我已经被困在这里几个小时了,任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: c makefile cmake


    【解决方案1】:

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

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

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

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

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

    查看cmake --help 以获取可用选项列表。 (特别是生成器目标是特定于平台的。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      相关资源
      最近更新 更多