CMake学习之windows下cmake生成nmake

简介: CMake学习之windows下cmake生成nmake

一、C++代码示例

//first_cmake.cpp
#include<iostream>
using namespace std;
int main(int argc ,char *argv[])
{
    cout<<"hello camke!"<<endl;
    return 0;
}

二、CMakeLists.txt编写

#CMakeLists.txt cmake文件名大小写不敏感
#指定cmake最低版本
cmake_minimum_required(VERSION 3.20)
#构建项目的名称
project(first_cmake)
#构建执行程序
add_executable(first_cmake first_cmake.cpp)

三、文件结构

四、编译

cmake -S . -B n -G "NMake Makefiles"

D:\Project\cmake\20230704\first_cmake>cd n
D:\Project\cmake\20230704\first_cmake\n>nmake                      //或者cmake --build n
Microsoft (R) 程序维护实用工具 14.16.27049.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。
[ 50%] Building CXX object CMakeFiles/first_cmake.dir/first_cmake.cpp.obj
first_cmake.cpp
?⒁? 包含文件:  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\iostream
?⒁? 包含文件:     C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\ios
?⒁? 包含文件:         C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\yvals_core.h
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xkeycheck.h
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\crtdefs.h
?⒁? 包含文件:            C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\sal.h
?⒁? 包含文件:             C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\concurrencysal.h
?⒁? 包含文件:            C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vadefs.h
?⒁? 包含文件:           C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt.h
?⒁? 包含文件:         C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\crtdbg.h
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcruntime_new_debug.h
?⒁? 包含文件:         C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\use_ansi.h
?⒁? 包含文件:        C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\limits.h
?⒁? 包含文件:        C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdlib
?⒁? 包含文件:         C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdlib.h
?⒁? 包含文件:          C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_malloc.h
?⒁? 包含文件:          C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_search.h
?⒁? 包含文件:           C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stddef.h
?⒁? 包含文件:          C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wstdlib.h
?⒁? 包含文件:         C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\math.h
?⒁? 包含文件:          C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_math.h
?⒁? 包含文件:        C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xtgmath.h
?⒁? 包含文件:       C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdio
?⒁? 包含文件:        C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
?⒁? 包含文件:         C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wstdio.h
?⒁? 包含文件:          C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h
?⒁? 包含文件:       C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\streambuf
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstring
?⒁? 包含文件:             C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_memcpy_s.h
?⒁? 包含文件:              C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcruntime_string.h
?⒁? 包含文件:            C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wstring.h
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\stdexcept
?⒁? 包含文件:           C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\exception
?⒁? 包含文件:             C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xstddef
?⒁? 包含文件:              C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\initializer_list
?⒁? 包含文件:            C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\malloc.h
?⒁? 包含文件:            C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcruntime_exception.h
?⒁? 包含文件:              C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_terminate.h
?⒁? 包含文件:           C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xstring
?⒁? 包含文件:            C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xmemory0
?⒁? 包含文件:             C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cstdint
?⒁? 包含文件:             C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\limits
?⒁? 包含文件:              C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\ymath.h
?⒁? 包含文件:              C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cfloat
?⒁? 包含文件:              C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\cwchar
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wconio.h
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wctype.h
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wdirect.h
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wio.h
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wprocess.h
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_wtime.h
?⒁? 包含文件:                C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\sys/stat.h
?⒁? 包含文件:                 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\sys/types.h
?⒁? 包含文件:             C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\new
?⒁? 包含文件:              C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\utility
?⒁? 包含文件:             C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xatomic0.h
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\typeinfo
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xlocinfo
?⒁? 包含文件:            C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\locale.h
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\memory
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xfacet
?⒁? 包含文件:         C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\system_error
?⒁? 包含文件:          C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xerrc.h
?⒁? 包含文件:         C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\share.h
[100%] Linking CXX executable first_cmake.exe
[100%] Built target first_cmake
D:\Project\cmake\20230704\first_cmake\n>

推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:

零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)

https://xxetb.xet.tech/s/VsFMs


相关文章
|
7月前
|
人工智能 机器人 编译器
【C++】Windows端VS code中运行CMake工程(手把手教学)
【C++】Windows端VS code中运行CMake工程(手把手教学)
431 0
|
2月前
|
存储 Linux 编译器
cmake的单目录和多目录的使用(Linux和Windows)
本文介绍了在Windows和Linux平台上使用CMake构建单目录和多目录项目的步骤,包括如何配置CMakeLists.txt文件以及如何生成和使用可执行文件、库文件。
56 2
|
6月前
|
Windows
逆向学习Windows篇:通过编写函数处理菜单消息
逆向学习Windows篇:通过编写函数处理菜单消息
40 0
|
6月前
|
安全 API C++
逆向学习Windows篇:C++中多线程的使用和回调函数的实现
逆向学习Windows篇:C++中多线程的使用和回调函数的实现
214 0
|
6月前
|
安全 API Windows
逆向学习Windows篇:文件操作详解
逆向学习Windows篇:文件操作详解
37 0
|
6月前
|
存储 数据安全/隐私保护 Windows
逆向学习Windows篇:进程句柄操作详解
逆向学习Windows篇:进程句柄操作详解
251 0
|
6月前
|
监控 安全 Windows
逆向学习Windows篇:lab的使用和生成过程,以及“dell”的导出函数和作用
逆向学习Windows篇:lab的使用和生成过程,以及“dell”的导出函数和作用
86 0
|
6月前
|
Windows
逆向学习Windows篇:动态加载与def导出
逆向学习Windows篇:动态加载与def导出
64 0
|
6月前
|
C++ UED 开发者
逆向学习 MFC 篇:视图分割和在 C++ 的 Windows 窗口程序中添加图标的方法
逆向学习 MFC 篇:视图分割和在 C++ 的 Windows 窗口程序中添加图标的方法
89 0
|
7月前
|
计算机视觉 Windows
OpenCV + CLion在windows环境下使用CMake编译, 出现Mutex相关的错误的解决办法
OpenCV + CLion在windows环境下使用CMake编译, 出现Mutex相关的错误的解决办法
315 0