标签:sudo file VSCode 配置 C++ ++ gdb printing pretty
在ubuntu的下配置C++环境很简单。但是课程作业又必须得做。
首先装VSCode
cd ~/Downloads
wgt https://vscode.cdn.azure.cn/stable/0ba0ca52957102ca3527cf479571617f0de6ed50/code_1.43.2-1585036376_amd64.deb
sudo dpkg -i code_1.43.2-1585036376_amd64.deb
安装gcc
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gcc
然后开始配置环境
先创建工作文件夹,然后用VSCode打开
mkdir ~/workspace
cd ~/workspace
code .
打开VScode中的控制台
这里可以在图形化界面创建测试代码,也可以像我这样写入,这里我增加了一个变量a,为了方便调试的时候查看
cat > helloWorld.cpp <<EOF
#include <iostream>
using namespace std;
int main(int argc,char** argv)
{
int a;
cin>>a;
cout<<"hello,cys"<<endl;
cout<<a<<endl;
return 0;
}
EOF
** 调试的时候先加上断点 **
F5 开始调试。同时当前文件下会成生成./vscode文件,文件会根据自己的配置自动生成。
(ctrl +F5 直接执行)
(注意Windows下需要添加环境变量,同时要注意ubuntu下是“\”,windows下“/”,否则可能会找不到编译工具。)
分别包含
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "g++-5 build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++-5 build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
{
"tasks": [
{
"type": "shell",
"label": "g++-5 build active file",
"command": "/usr/bin/g++-5",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0"
}
我把断点设置在 第四行
调试
左上角是一些变量查看的地方
左下角是栈之类的信息
F10(next)
F11(step into)
F12(step out)
具体的就像这样
标签:sudo,file,VSCode,配置,C++,++,gdb,printing,pretty 来源: https://www.cnblogs.com/cyssmile/p/12588767.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。