Windows: Powershell+CMAKE+MinGW
文章目录
- Powershell是命令行控制工具
- Make和CMake是构建工具
- MSVC是指微软的VC编译器。 MinGW是指是Minimalist GNU on Windows的缩写,MinGw是windows版本的gcc集合,MinGW 还包含有一些其他的 GNU 程序开发工具
Powershell
powershell是cmd的超集
常用命令
tree | 显示目录文件夹 |
---|---|
tree /f | 显示目录文件夹及文件结构 |
get-childitem | 显示当前目录下的文件 |
Start-Process powershell -Verb runAs | 打开管理员模式窗口 |
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