Preface
Maybe you don't know much about msys2, but as a programmer, you know MinGW, and Msys2 integrates MinGW, while Msys2 has some other features, such as Package Manager.
Msys2 can build a perfect Linux-like environment under Windows, including Bash, vim, GCC, make, and so on, through the Package Manager to add and uninstall
MSYS2 Package Manager is the use of Pacman, used to ArchLinux should know Pacman.
Our goal now is to integrate a compilation tool installation for MAKE+GCC+GDB
Download Address:
Msys2
If it is EXE, double-click the installation directly, if it is zip, directly to the installation of the location can be. Then double-click Msys2.exe to run
Modify Pacman Source
Used archlinux should know, Pacman in the installation, if the source is not set well, 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
These three documents
Mirror source I recommend using the following two: Tsinghua University of Science and Technology of China
The following is an example of Tsinghua University:
Open the Mirror station of Tsinghua University, find the MSYS2 item, and click on the help below.
MSYS2 mirroring use Help to include the
schema
mingw:i686, x86_64
msys:i686, x86_64
installation
please visit the distrib/directory (x86_64, i686) under the mirrored directory. Locate the file named msys2-< Schema >-< date >.exe (such as Msys2-x86_64-20141113.exe) and download the installation.
Pacman Configuration
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 file:
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch
then perform pacman-sy refresh package data.
Installation can be skipped directly to see Pacman can be, referring to this modification
The method of University of Science and Technology of China can refer to Tsinghua. Download Tool Kit
Download Toolkit This part is pure pacman knowledge, the instructions involved are:
Pacman-sy Update package data
Pacman-syu Update All
PACMAN-SS XX Inquiry software xx information
pacman-s xx installation software xx download make
We first use the command PACMAN-SS make to query the full make package name
We can see that each software is roughly divided into three categories: Mingw32, Mingw64, Msys, if you want to download MinGW then to correspond to their own system download, 32-bit and 64-bit to distinguish
We download the Msys class on the line. For example, we found the make is this:
msys/automake1.9 1.9.6-2 (base-devel)
A GNU tool for automatically creating makefiles msys/cmake 3.6.2-1
A Cross-platform Open-source make system
msys/colormake-git r8.9c1d2e6-1
colorized build output
Msys/make 4.2.1-1 (Base-devel) [installed]
GNU made utility to maintain groups of programs Msys/make-git
GNU make utility to maintain groups of programs
Msys/perl 5.24.1-2 (base-devel)
That's msys/make, so when we install it we just need to enter:
Pacman-s Msys/make
or direct input
Pacman-s make
The default installation msys/make download gcc
Let's 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-w64
Mingw64/mingw-w64-x86_64-lcov 1.12-1
Front-End for GCC ' s coverage testing tool gcov \
MSYS/GCC 6.3.0-1 (Msys2-devel) The
GNU Compiler collection-c and C + + frontends Msys/gcc-fortran
-6.3.0-1 (msys2-devel)
fortran Front-End for GCC
That's msys/gcc, so when we install it we just need to enter:
Pacman-s MSYS/GCC
Or
Pacman-s GCC
Test
After installation we test:
Make-v
Displays a description similar to the following for installation success:
GNU make 4.2.1
for X86_64-pc-msys compile
Copyright (C) 1988-2016 free Software Foundation, Inc.
License: GPLV3+:GNU general Public License version 3rd or newer
Then test GCC:
The uses built-in specs. COLLECT_GCC=GCC collect_lto_wrapper=/usr/lib/gcc/x86_64-pc-msys/6.3.0/lto-wrapper.exe target: X86_64-pc-msys configured as:/msys _scripts/gcc/src/gcc-6.3.0/configure--build=x86_64-pc-msys--prefix=/usr--libexecdir=/usr/lib--enable-bootstrap --enable-shared--ENABLE-SHARED-LIBGCC--enable-static--enable-version-specific-runtime-libs--with-arch=x86-64-- With-tune=generic--disable-multilib--enable-__cxa_atexit--with-dwarf2--enable-languages=c,c++,fortran,lto-- Enable-graphite--enable-threads=posix--enable-libatomic--enable-libcilkrts--enable-libgomp--enable-libitm-- Enable-libquadmath--enable-libquadmath-support--ENABLE-LIBSSP--disable-win32-registry--disable-symvers-- With-gnu-ld--with-gnu-as--disable-isl-version-check--enable-checking=release--without-libiconv-prefix--
Without-libintl-prefix--with-system-zlib--enable-linker-build-id--with-default-libstdcxx-abi=gcc4-compatible Threading model: POSIX gcc version 6.3.0 (GCC)
Other software is so play, I will not introduce. 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
Then we switched the Msys directory to this c file through the CD command.
After execution
$GCC Demo.c-o Demo
If the compilation has no errors, it generates Demo.exe in the current directory and then runs:
$./demo.exe
You can see the results of the run
The running process is as follows:
Xml@desktop-b0ss2ke msys/f/xml/test/demo1
$ gcc demo.c-o demo
xml@desktop-b0ss2ke msys/f/xml/test/demo1
$ ls
demo.c demo.exe
xml@desktop-b0ss2ke msys/f/xml/test/demo1
$./demo.exe
AbcDEF
Of course, if we need to do detailed analysis of the code, in the compile time with the-G parameter, and then through the objdump to analyze the assembly source code it
xml@desktop-b0ss2ke msys/f/xml/test/demo1 $ gcc demo.c-g-o demo xml@desktop-b0ss2ke msys/f/xml/test/demo1 $ objd Ump-f./demo.exe/demo.exe: File format pei-x86-64 architecture: I386:X86-64, Flag 0x0000013a:exec_p, Has_debug, has_syms, HAS_LOCALS , d_paged start address 0x0000000100401000 xml@desktop-b0ss2ke Msys/f/xml/test/demo1 $ objdump-s./demo.exe: File
Pei-x86-64 disassembly of section. Text: ...
00000001004010e0 <main>: #include <stdio.h> int main () {1004010e0:55 push%RBP 1004010e1:48 e5 mov%rsp,%rbp 1004010e4:48-EC-sub $0X20,%RSP 1004
010e8:e8 callq 100401120 <__main> printf ("abcdef\r\n"); 1004010ed:48 8d 0d 3c 1f Lea 0X1F3C (%rip),%RCX # 100403030 <.rdata> 1004010f4:e8 37 00 0 0 callq 100401130 <puts> 1004010f9:b8 mov $0x0,%eax} ....
Of course we can also install GDB and then debug the code via GDB