Using MSYS2 + vs code to configure C + + compilation environments in Windows 10 environments

Source: Internet
Author: User

Not too much description msys2 vs. code, since you need to install a language of the compilation environment, you must be familiar with these two;

1. Install Msys2 first; (Download how many bits of MSYS2 on the installation of the number of MinGW, I installed 32-bit)

Download Connection address: http://msys2.github.io/

Follow the official website documentation, step-by-step installation.

2. Modify Msys source (recommended modification)

Modify Reference Address:
https://mirrors.tuna.tsinghua.edu.cn/help/msys2/(click to view)

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 the file:

Server = HTTPS ://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch


then perform pacman-sy refresh package data.

, after the configuration is good, input Pacman-syu update msys2 software package;

After the update, install the Gcc,gdb,make package separately.

Note: When you update Msys2, view, MSYS2 installation directory, more than a lot of. exe files;

It's best to match the number of msys2 you install, 32-bit msys2, and you start the Mingw32.exe; 64-bit empathy.

, start to install gcc,gdb,make;

In the form, enter each:

pacman-s MINGW32/MINGW-W64-I686-GCC

pacman-s mingw32/mingw-w64-i686-gdb

pacman-s Mingw32/mingw-w64-i686-make

After the installation is complete, configure the MINGW32 environment variables:

Path add "C:\msys32\mingw32\bin;"

3. Verification: windows+r = cmd

In the cmd form, enter each:

Gcc-v

Gdb-v

See if GCC and gdb install OK and their version information;

4. Download and install vs code (address:
https://code.visualstudio.com/c?utm_expid=101350005-27.GqBWbOBuSRqlazQC_nNSRg.2&utm_referrer=https%3A%2F% 2fcode.visualstudio.com%2fdocs%2f%3fdv%3dwinzip)

5. Configure the VS code C + + compilation Environment

Open vs Code,

Selecting a C + +-related configuration will give you an extra. vscode file in the local area and a Launch.json file. This is configured to

How to configure, you can refer to my profile content, or refer to the official website documentation (HTTPS://CODE.VISUALSTUDIO.COM/DOCS/LANGUAGES/CPP)

Launch.json:

{"Version": "0.2.0", "configurations": [{"Name": "C + + Launch", "type": "cppdbg" , "Request": "Launch", "Targetarchitecture": "x86", "program": "${workspaceroot}/a.exe "," args ": []," stopatentry ": false," CWD ":" ${workspaceroot} "," Environme NT ": []," externalconsole ": True," Midebuggerpath ":" C:/msys32/mingw32/bin/gdb.exe "," p
                Relaunchtask ":" g++ "," Linux ": {" Mimode ":" GdB "}," OS X ": {
        ' Mimode ': ' Lldb '}, ' windows ': {' mimode ': ' GdB '}}, {"Name": "C + + Attach", "type": "cppdbg", "Request": "Launch", "Targ Etarchitecture ":" x64 "," program ":" ${workspaceroot}/a.exe "," args ": []," stopatentry ": false," CWD ":" ${workspaceroot} "," Environment ": []," ProcessID ":" ${command.pickprocess} "," ex
            Ternalconsole ": false," Prelaunchtask ":" g++ "," Linux ": {" Mimode ":" GdB " "OS X": {"Mimode": "Lldb"}, "Windows": {"Mimod E ":" GdB "}}]}

Attention

The midebuggerpath node is configured to go with the local path all the time.

After the configuration, F5 start debugging, this time, will let you configure Tasks.json. will appear, a Drop-down box, you choose a random (purpose, is to appear Tasks.json file), so, directly configure Tasks.json file can;

5. Configure Tasks.json Files:

{
    "version": "0.1.0", "
    Command": "g++",
    "args": ["G", "${file}"],
    "Problemmatcher": {
        "owner": "CPP",
        "filelocation": ["Relative", "${workspaceroot}"],
        "pattern": {
            "regexp": "^ (. *):(\\d+):(\\d+): \ \s+ (Warning|error): \\s+ (. *) $ ",
            " file ": 1,
            " line ": 2,
            " column ": 3,
            " severity ": 4,
            " message " : 5
        }
    }
}

After the configuration is done,
one point to note is that the configuration under #include头文件的路径, vs code, is often prompted not to find the file path for include.
Put the mouse on the green wavy line, there will be a light bulb, that is the entrance to the configuration file, do not forget to configure;

C_cpp_properties.json:

{"Configurations": [{"Name": "Mac", "Includepath": ["/usr/include" ], "Browse": {"limitsymbolstoincludedheaders": true, "Databasefi Lename ":" "}}, {" Name ":" Linux "," Includepath ": ["
                /usr/include "]," browse ": {" limitsymbolstoincludedheaders ": true,
                ' DatabaseFileName ': ' '}}, {' name ': ' Win32 ', ' Includepath ': [
                "c:/msys32/mingw32/include/c++/6.1.0/*", "c:/msys32/mingw32/i686-w64-mingw32/include/*", "C:/msys32/mingw32/include"], "browse": {"Limitsymbolstoincludedheade Rs ": True," DatabaseFileName ":" "}}]," Clang_format ": {" style ":" F Ile "," fallback-Style ": LLVM", "Sort-includes": false}} 

Original link: Use Msys2 + vs code to configure C + + compilation environment in Windows 10 environment

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.