This blog post demonstrates in Ubuntu Install in virtual machine Vs Code And configure C++/C Environmental Science
<> The first step : Install and run Vs Code
<> Search in the app store visual studio code And click install Install
<> Input at the terminal after installation code It will work Vs Code
<> Step two : install gcc/g++ and gdb
Open the terminal and input the following commands and your own password in turn
sudo apt-get update sudo apt-get install gcc sudo apt-get install g++ sudo
apt-get install gdb
After finishing, you can enter the command to check whether the installation is successful
gcc -v gdb -v g++ -v
<> The third step : Install the necessary Vs Code plug-in unit
open Vs Code Search for installation C/C++ and Code Runner plug-in unit
<> Step four : Try running the program
Because it's installed Code Runner plug-in unit , You can run the program directly ( But it can't be debugged yet ), Here's how to use it Code Runner Run the program
I am here home A new one has been created in the folder CAndC++Code Used to store the original code file written later , Place the folder in Vs
code Open and create a new one in test.cpp File for testing ( Please ignore the one on the left .vscode folder , This step is not needed yet )
Click the triangle button in the upper right corner to run the program
be careful : Sometimes you will find that the program can't run normally , At this time, you may need to click the gear in the lower left corner Manage And choose (settings)
search code runner run in terminal And tick the one you find
Then close it vscode Then open it again and click the triangle to use it Code Runner You can run the program
<> Step five : Try debugging the program
Light has coderunner It can't be debugged , At the ready CAndC++Code New in folder .vscode folder , stay .vscode Create two new files in the folder . One called launch.json, The other is called tasks.json. In the future, if you want to debug in other folders, you have to rebuild them .vscode Subfolders and configuration
Copy the following code to launch.json And save it
{ "version": "0.2.0", "configurations": [ { "name": "C/C++", "type": "cppdbg",
"request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment":
[], "externalConsole": false, "MIMode": "gdb", "preLaunchTask": "compile",
"setupCommands": [ { "description": "Enable pretty-printing for gdb", "text":
"-enable-pretty-printing", "ignoreFailures": true } ] } ] }
Copy the following code to tasks.json Zhongqu .
notes : If necessary, yes c Language is gcc Put the following command Item by g++ Change to gcc
{ "version": "2.0.0", "tasks": [{ "label": "compile", "command": "g++",
"args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ],
"problemMatcher": { "owner": "cpp", "fileLocation": [ "relative",
"${workspaceRoot}" ], "pattern": { "regexp":
"^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2,
"column": 3, "severity": 4, "message": 5 } }, "group": { "kind": "build",
"isDefault": true } } ] }
Now select debug on the left and click the green arrow in the upper left corner , Set a breakpoint for debugging
And then you'll find it's ready to debug
That's it C/C++ Configuration of , Can be written , Run and debug C++/C The procedure is over
Technology
Daily Recommendation