Every time you change a computer to write C + +, it is necessary to find the configuration, is cumbersome. This time I write a blog, record the relevant configuration process.
Installing the compiler
Open the following Web site http://www.msys2.org/
, download the 64-bit MYSYS2
, and follow the steps on the home page to install the software. After complete, go to the /etc/pacman.d
directory to modify the following 3 files respectively.
The contents of the Mirrorlist.mingw32 file are:
Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
The contents of the Mirrorlist.mingw64 file are:
Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/
The contents of the Mirrorlist.msys file are:
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/
Then enter the following command to update the system.
cd ~pacman -Syu
Enter the command again to install the C + + tool.
pacman -S mingw-w64-x86_64-toolchain
The following prompt appears, selecting 3,9,13. The file is a bit large and patiently waiting to be downloaded.
When completed, e:\Softwares\msys64\mingw64\bin\
add to the system environment. Note: The e:\Softwares
catalogue is tuned according to the actual situation.
Installing Vscode
This tool we choose Vscode, convenient and practical, although the C + + plug-in weak point, but Microsoft development, will not be poor to where to go. Select the plugin after installation is complete c/c++
. See.
Open the software, then in the File
menu, click Add Folder to Workspace...
, select a directory as a folder to write C + + code later, here we assume that the selected folder is cpp
. Create a new directory under CPP, .vscode
and then create a new folder under the .vscode
directory, task.json
c_cpp_properties.json
launch.json
3 files. See.
tasks.cpp
The contents are as follows:
{ "Version": "2.0.0", "Tasks": [ { "Label": "Compile", "command": "g++", "args": [ "-G", "${file}", //Specify compiling source code files "-O", "${filedirname}/${filebasenamenoextension}.exe", // Specifies the output file name, without which the default output A.exe "-GGDB3", // information about building and debugging "-wall", // turn on additional warnings "-STATIC-LIBGCC", // Static links "-std=c++17", // Use the latest C + + -Standard "-wno-format", "-FEXEC-CHARSET=GBK", //console form output character encoding guaranteed to display Chinese correctly "-finput-charset=utf-8" //input compiler text encoding default to UTF-8 ], "Type": "Shell", "Group": { "Kind": "Build", "IsDefault": true }, "Presentation": { "echo": true, "Reveal": "Always", // The policy for displaying compilation information in terminal can be Always,silent,never "Focus": false, "Panel": "Shared" // compile information for different files share a terminal panel }, "Problemmatcher": { "owner": "CPP", "Filelocation": [ "Relative", "\\" ], "pattern": { "RegExp": "^(.*):(\\d+):(\\d+):\\s+ (warning|error):\\s+ (. *) $ ", "File": 1, "line": 2, "column": 3, "Severity": 4, "Message": 5 } } } ]}
c_cpp_properties.json
The content of:
{ "Configurations": [ { "Name": "Win32", "Intellisensemode": "Clang-x64", "Includepath": [ "${workspacefolder}", "e:/softwares/msys64/mingw64/include/c++/7.3.0/" ], "defines": [ "_DEBUG", "UNICODE", "__gnuc__=7", "__cdecl=__attribute__ ((__cdecl__))" ], "Browse": { "Path": [ "${workspacefolder}", "e:/softwares/msys64/mingw64/include/c++/7.3.0/" ] }, "Limitsymbolstoincludedheaders": true, "DatabaseFileName": "", "Cstandard": "C11", "Cppstandard": "C++17" } ], "Version": 3}
launch.json
For code debugging, it does not work at this time.
Run code
After completing the above work, in the CPP directory, write a test.cpp file, and then press Ctrl+Shift+B
, will generate the Test.exe file. The test.exe is then executed at the terminal.
Vscode Configuring C + +