How to configure the C language compilation environment for vscode
This article mainly introduces vscode how to configure the c language compilation environment, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it.
Download the MinGW-W64 GCC-8.1.0 compiler (this article installs x86_64-win32-seh)
II. Environmental configuration
Open your mingw-w64 installation directory. I install it by default in C:\ Program Files (x86). The MinGW-W64 in it is the installed compiler. Add the bin folder to the path, and mine is C:\ Program Files (x86)\ mingw64\ bin. Just add this to the path.
Path joining method:
After joining, it is recommended to restart the computer.
Install plug-ins related to VSCode cpp
C++ plug-in
Restart the vscode software.
Configure the .vscode file of C++
Create a new folder in the place where you write the code and create a new folder in it, and then create a .vscode folder in the folder
Then create four files in the .vscode folder as shown above, with the following file names:
C_cpp_properties.json
Launch.json
Tasks.json
Please modify the file path according to the location of the installation (do not modify it if you are like me)
Launch.json
{"version": "0.2.0", "configurations": [{"name": "(gdb) Launch", / / configuration name, "type": "cppdbg", / / configuration type will be displayed in the launch configuration drop-down menu. Here only cppdbg "request": "launch", / / request configuration type Can be launch (startup) or attach (additional) "program": "${workspaceFolder} / ${fileBasenameNoExtension} .exe", / / the path of the program to be debugged is "args": [], / / the command line argument passed to the program when debugging is generally set to "stopAtEntry": false, / / when the program is set to true, the program will be paused at the entrance of the program It is generally set to false "cwd": "${workspaceFolder}", / / the working directory when debugging the program. Generally, it is ${workspaceRoot}, that is, the directory where the code is located. WorkspaceRoot has been deprecated. It is now changed to workspaceFolder "environment": [], "externalConsole": true, / / whether the console window is displayed when debugging. Generally set to the path of "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86) / mingw64/bin/gdb.exe", / / miDebugger of the true display console. Note that the path here corresponds to "preLaunchTask": "Gmail +", / / the task executed before the start of the debugging session, which is generally a compiler. C++ is gcc setupCommands: [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": false}]}]}
Tasks.json
If you can't find a file, such as this:
Replace "${workspaceFolder}" with "\" or "/ /"
{"version": "2.0.0", "command": "cpp +", "args": ["- g", "${file}", "- o", "${fileBasenameNoExtension} .exe"], / / compilation command parameters "problemMatcher": {"owner": "cpp", "fileLocation": ["relative" "${workspaceFolder}"], "pattern": {"regexp": "^ (. *): (\\ d +): (\\ d +):\\ s + (warning | error):\\ s + (. *) $", "file": 1, "line": 2, "column": 3, "severity": 4 "message": 5}
C_cpp_properties.json
The "includepath" setting question path acquisition method is: cmd-- "gcc-v-E-x C++-
If the first goes wrong, please use the second.
{"configurations": [{"name": "Win32", "includePath": ["${workspaceRoot}", "C:/Program Files (x86) / mingw64/include/**", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../x86_64-w64-mingw32/include"], "defines": ["_ DEBUG", "UNICODE", "_ _ GNUC__=6" "_ _ cdecl=__attribute__ ((_ _ cdecl__)"], "intelliSenseMode": "msvc-x64", "browse": {"limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "path": ["${workspaceRoot}" "C:/Program Files (x86) / mingw64/include/**", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../x86_64-w64-mingw32/include"]}] "version": 4}
The second kind
{"configurations": [{"name": "Win32", "includePath": ["C:/Program Files (x86) / mingw64/include/**", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed" "C:/Program Files (x86) / mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../x86_64-w64-mingw32/include"], "browse": {"limitSymbolsToIncludedHeaders": true, "databaseFilename": ""}}], "version": 4}
5. Configure the .vscode file of c language
Create a new folder and a new folder in the place where you write the code, and then create a .vscode folder in the folder
Then create four files in the .vscode folder as shown above, with the following file names
Launch.json
Tasks.jsonlaunch.json
{"version": "0.2.0", "configurations": [{"name": "(gdb) Launch", / / configuration name, "type": "cppdbg", / / configuration type will be displayed in the launch configuration drop-down menu. Here only cppdbg "request": "launch", / / request configuration type Can be launch (startup) or attach (additional) "program": "${workspaceFolder} / ${fileBasenameNoExtension} .exe", / / the path of the program to be debugged is "args": [], / / the command line argument passed to the program when debugging is generally set to "stopAtEntry": false, / / when the program is set to true, the program will be paused at the entrance of the program It is generally set to false "cwd": "${workspaceFolder}", / / the working directory when debugging the program. Generally, it is ${workspaceRoot}, that is, the directory where the code is located. WorkspaceRoot has been deprecated. It is now changed to workspaceFolder "environment": [], "externalConsole": true, / / whether the console window is displayed when debugging. Generally set to the path of true display console "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86) / mingw64/bin/gdb.exe", / / miDebugger. Note that it corresponds to the path of "preLaunchTask": "gcc", / / the task executed before the start of the debugging session, which is generally a compiler. C++ is gcc setupCommands: [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": false}]}]}
Tasks.json
{"version": "2.0.0", "command": "gcc", "args": ["- g", "${file}", "- o", "${fileBasenameNoExtension} .exe"]} Thank you for reading this article carefully. I hope the article "how to configure c language compilation environment for vscode" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!