Windows Powershell+CMAKE+MinGW

Windows: Powershell+CMAKE+MinGW

  1. Powershell是命令行控制工具
  2. Make和CMake是构建工具
  3. MSVC是指微软的VC编译器。 MinGW是指是Minimalist GNU on Windows的缩写,MinGw是windows版本的gcc集合,MinGW 还包含有一些其他的 GNU 程序开发工具

Powershell

powershell是cmd的超集

PowerShell

常用命令

tree 显示目录文件夹
tree /f 显示目录文件夹及文件结构
get-childitem 显示当前目录下的文件
Start-Process powershell -Verb runAs 打开管理员模式窗口

删除文件




CMake介绍与安装

CMake

官网 下载

规范:大小写不敏感,约定俗成用大写

常用命令

构建MinGW文件:cmake -G "MinGW Makefiles"

构建MSVC文件:cmake -G "MinGW Makefiles"

外部构建:cmake -G -B ./build

构建文件+外部构建+安装路径 一起写:cmake -B ./build -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX=/test

编译:mingw32-make

修改安装路径:cmake -D CMAKE_INSTALL_PREFIX=/test

编译并安装:mingw32-make install

CMake教程

样例流程

构建

准备:写一个cpp文件,和一个CMakeLists.txt

#main.cpp
#include <iostream>
int main(){
   
	std::cout << "hello word" << std::endl;
}
PROJECT (HELLO)
SET(SRC_LIST main.cpp)
MESSAGE(STATUS "This is BINARY dir" ${
   HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir" ${
   HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ${
   SRC_LIST})

Powershell输入:cmake .

在windows下直接使用cmake. 生成的是支持Visual Studio的MSVC的sln项目文件

cmake -G "MinGW Makefiles" #构建支持MinGW的文件
cmake -G "NMake Makefiles" #构建支持Visual Studio的MSVC的文件
# 在windows系统下,使用 cmake . 默认生成的是VS的sln项目文件

构建支持Visual Studio的MSVC的文件:cmake -G "NMake Makefiles" 或者 windows下直接使用 cmake .

PS C:\Users\Zhang> cd D:\code_projects\OddJobs\CMAKE_LEARN\Test21\
PS D:\code_projects\OddJobs\CMAKE_LEARN\Test21> cmake .
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.29.30147.0
-- The CXX compiler identification is MSVC 19.29.30147.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/software/code/VS2019/VC/Tools/MSVC/14.29.30133/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: D:/software/code/VS2019/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- This is BINARY dirD:/code_projects/OddJobs/CMAKE_LEARN/Test21
-- This is SOURCE dirD:/code_projects/OddJobs/CMAKE_LEARN/Test21
-- Configuring done
-- Generating done
-- Build files have been written to: D:/code_projects/OddJobs/CMAKE_LEARN/Test21
PS D:\code_projects\OddJobs\CMAKE_LEARN\Test21>

构建支持MinGW的文件

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4mTcx3fr-1687752064842)(Windows%20Powershell+CMAKE+MinGW%2008edcd49fc894b03bfcf07b2c3b3ff50/Untitled.png)]

PS D:\code_projects\OddJobs\CMAKE_LEARN\Test21> cmake -G “MinGW Makefiles”
CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.

-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/library/mingw64/bin/gcc.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: D:/library/mingw64/bin/c++.exe 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值