Windows上mingw C/C++环境搭建

MSYS2和CMake搭建C/C++环境 参考指南

准备材料


如何下载

1.png

点击即可下载,之后莽点下一步即可安装

2.png

根据系统架构选择对应的版本下载,之后双击安装即可

正式开始

  1. 打开安装的MSYS2 MSYS, 更换软件源 (选择任意即可)
    1
    2
    3
    4
    5
    6
    # tuna mirror 清华软件源
    sed -i "s#mirror.msys2.org/#mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*

    # ustc mirror 中科大软件源
    sed -i "s#mirror.msys2.org/#mirrors.ustc.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*

3.png

4.png

  1. 更新一下软件包
    1
    pacman -Syyu
    遇到 :: Proceed with installation? [Y/n] 的类似问题时输入y即可

5.png

  1. 安装mingw
    1
    2
    3
    pacman -S base-devel 
    pacman -S mingw-w64-x86_64-toolchain

    Enter a selection (default=all): 输入回车即可
    6.png

4. 配置系统环境

找到安装目录的mingw64路径
7.png

计算机右键属性 -> 高级系统设置 -> 环境变量 -> 系统变量 -> path -> 你的路径
8.png
9.png
10.png
11.png

最后验证

1
2
cmake --version
gcc -v

12.png

拓展阅读

MSYS2 是什么?
MSYS2 is a collection of tools and libraries providing you with an easy-to-use environment for building, installing and running native Windows software.

It consists of a command line terminal called mintty, bash, version control systems like git and subversion, tools like tar and awk and even build systems like autotools, all based on a modified version of Cygwin. Despite some of these central parts being based on Cygwin, the main focus of MSYS2 is to provide a build environment for native Windows software and the Cygwin-using parts are kept at a minimum. MSYS2 provides up-to-date native builds for GCC, mingw-w64, CPython, CMake, Meson, OpenSSL, FFmpeg, Rust, Ruby, just to name a few.

To provide easy installation of packages and a way to keep them updated it features a package management system called Pacman, which should be familiar to Arch Linux users. It brings many powerful features such as dependency resolution and simple complete system upgrades, as well as straight-forward and reproducible package building. Our package repository contains more than 2600 pre-built packages ready to install.

For more details see ‘What is MSYS2?’ which also compares MSYS2 to other software distributions and development environments like CygwinWSLChocolateyScoop, … and ‘Who Is Using MSYS2?’ to see which projects are using MSYS2 and what for.

MSYSY2 MSYS 用来管理和安装包的
MSYSY2 MinGW 32-bit 编译32位程序,库链接到msvcrt上
MSYSY2 MinGW 64-bit 编译64位程序,库链接到msvcrt上
MSYSY2 MSYS UCRT 64-bit 编译64位程序,库链接到ucrt上

CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.


Windows上mingw C/C++环境搭建
http://cvrain.cloudvl.cn/2022/12/11/Cpp/Tips-mingw/
作者
ClaudeRainer
发布于
2022年12月11日
许可协议