遇到这个问题的场景是:

PS C:\Users\Administrator\Desktop\Cplus\test\build> cmake ..  
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.27.29111.0
-- The CXX compiler identification is MSVC 19.27.29111.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Administrator/Desktop/Cplus/test/build
PS C:\Users\Administrator\Desktop\Cplus\test\build> make      
make: *** 没有指明目标并且找不到 makefile。 停止。

然后生成了一堆???

在这里插入图片描述
然而我想要的是带有makefile文件的那种,之前是在ubuntu上跑的那种

发现了问题

可能是由于我之前安装了Visual Studio 2019,也或者是windows10默认,我并没有去探究具体的

so,CMake会生成MSVC解决方案。在构建目录中检查 .sln 文件。

可以看到上图就有.sln结尾的文件

解决方法

指定解决方案是Unix 平台的Makefiles

cmake .. -G "Unix Makefiles" (第一次运行cmake时)

后面就直接cmake ..

PS C:\Users\Administrator\Desktop\Cplus\test\build> cmake ..  -G "Unix Makefiles" 
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/cygwin64/bin/cc - skipped
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/cygwin64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Administrator/Desktop/Cplus/test/build
PS C:\Users\Administrator\Desktop\Cplus\test\build> make
Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main.exe
[100%] Built target main
PS C:\Users\Administrator\Desktop\Cplus\test\build> .\main.exe
This is a test file!

可以看到这就是我想要的,完美解决!!!
在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐