Win7 / Win10 下 msys64 安装 MinGW-w64 工具链

1. 安装msys64

下载MSYS2安装文件

安装到指定目录, 例如C:\msys64

2. 命令行更新

运行msys2.exe打开命令行窗口, 执行命令

pacman -Syu

如果出现这个错误

error: failed to update mingw32 (unable to lock database)
error: failed to update mingw64 (unable to lock database)
error: failed to update msys (unable to lock database)
error: failed to synchronize all databases

可能是之前意外关闭, db.lck文件未清除, 执行以下命令

rm -f /var/lib/pacman/db.lck

3. 修改安装源

Windows下进入msys64/etc/pacman.d/, MSYS64下则是 /etc/pacman.d/

需要修改三个文件, 都添加在Server列表第一行

mirrorlist.mingw32

Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/

mirrorlist.mingw64

Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/

mirrorlist.msys

Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/

4. 命令行安装

在msys2窗口内, 命令行执行

pacman -S --needed base-devel mingw-w64-x86_64-toolchain git mingw-w64-x86_64-cmake

等完成之后就有了mingw64 工具链, 会出现选择提示, 默认全部, 安装需要1.xGB空间, 空间足够的话就全部安装吧, 还可以选择的软件有 git mercurial cvs wget p7zip perl ruby python2

5. 配置

将mingw64的路径(例如 C:\msys64\mingw64\bin )添加到PATH目录, 添加完后, 在Eclipse CDT的Perference C/C++ -> Core Build Toolchains 中Available Toolchains就能看到GCC了

Update 2019-11-12: 配置GNU99, 打开 project properties. -> C/C++Build -> Settings, Tool Settings 标签页-> GCC C compiler -> Miscellaneous. 在 other flags 输入框, 添加 -std=c99 , Apply&Close. 配合 #include <stdbool.h> 就可以使用 bool, true, false关键字了.

参考

posted on 2019-11-06 19:33  Milton  阅读(2715)  评论(0编辑  收藏  举报

导航