Windows Builds GCC development environment (MSYS2)

Source: Internet
Author: User

Objective

You may not know msys2 very well, but as a programmer you must know MinGW, and Msys2 integrates MinGW, while Msys2 has some other features, such as Package Manager. Msys2 can build a perfect class Linux environment under Windows, including Bash, vim, GCC, make and other tools can be added and uninstalled through the Package Manager Msys2 Package Manager is the use of Pacman, Used archlinux should all know Pacman. Our goal now is to integrate MAKE+GCC+GDB with a compilation tool

Installation

: http://mirror.bit.edu.cn/msys2/Base/x86_64/

If it is exe, directly double-click the installation, if it is zip, unzip directly to the installation of the place. Then double-click Msys2.exe to run

Modify Pacman Source

Used archlinux should know, Pacman in the installation, if the source is not set, the download is very slow. The files that need to be modified are:

1. \etc\pacman.d\mirrorlist.mingw32

2. \etc\pacman.d\mirrorlist.mingw64

3. \etc\pacman.d\mirrorlist.msys

Configuration of the Pacman
Edit/etc/pacman.d/mirrorlist.mingw32, add at the beginning of the file:

Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686
Edit/etc/pacman.d/mirrorlist.mingw64, add at the beginning of the file:

Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64
Edit/etc/pacman.d/mirrorlist.msys, add at the beginning of the file:

Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch
Then execute pacman-sy to refresh the package data.

Download Tool Kit

Download Toolkit This part is purely pacman knowledge, the instructions involved are: Pacman-sy update package Data pacman-syu update all PACMAN-SS xx query software xx information pacman-s XX installation software xx

Download make

We'll start by ordering PACMAN-SS make to query the full made package name we can see that each software is broadly divided into three broad categories: Mingw32, Mingw64, Msys, if you want to download MinGW then it will be corresponding to their own system download, 32-bit and 64-bit to distinguish between We can download the Msys class. For example, the make we searched for is this:

msys/automake1.9 1.9.6-2 (base-devel)    A GNU tool for automatically creating Makefilesmsys/cmake 3.6.2-1    A cross-platform open-source make systemmsys/colormake-git r8.9c1d2e6-1    Colorized build outputmsys/make 4.2.1-1 (base-devel) [已安装]    GNU make utility to maintain groups of programsmsys/make-git 4.1.8.g292da6f-1    GNU make utility to maintain groups of programsmsys/perl 5.24.1-2 (base-devel)

That is msys/make, so we only need to enter when installing:

pacman -S msys/make

or enter directly

pacman -S make

The Msys/make will be installed by default

Download gcc

We'll start by ordering pacman-ss gcc to query the full GCC package name

mingw64/mingw-w64-x86_64-gcc-objc 6.3.0-1 (mingw-w64-x86_64-toolchain)    GNU Compiler Collection (ObjC,Obj-C++) for MinGW-w64mingw64/mingw-w64-x86_64-lcov 1.12-1    front-end for GCC‘s coverage testing tool gcovmsys/gcc 6.3.0-1 (msys2-devel)    The GNU Compiler Collection - C and C++ frontendsmsys/gcc-fortran 6.3.0-1 (msys2-devel)    Fortran front-end for GCC

That is MSYS/GCC, so we only need to enter when installing:

pacman -S msys/gcc

Or

pacman -S gcc

Compiling tests

Let's start with a new demo.c file and write a test code:

#include <stdio.h>int main () {    printf ("abcdef\r\n");}

Save and then we switch the Msys directory to this c file by using the CD command to execute

$gcc demo.c -o demo

If the compilation has no errors, then the Demo.exe is generated in the current directory and then run:

$./demo.exe

56671839

Windows Builds GCC development environment (MSYS2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.