deepin系统下给vscode配置c++开发环境

最近想在上使用vscode写C++,不喜欢每次都新建项目,所以选择使用vscode编辑+插件调试+Linux终端

配置步骤

其实现在的vscode配置c/c++已经很简单了,官方教程是很详细的
这里做一下简单的记录

0 新建一个cpp文件,简单的hello world即可

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main(){
cout<<"hello world"<<endl;
for(int i=0;i<10;i++){
cout<<i<<endl;
}
}

1 Ctrl + Shift + B(快捷键) 配置launch.json文件
2 F5 配置task.json文件
注意preLaunchTask选项和和launch.json中label的要保持一致

问题解决

问题之错误提示
Unable to open ‘libc-start.c’: Unable to read file (Error: File not found (/build/glibc-kAz5Pl/glibc-2.27/csu/libc-start.c)).
根据github上的issue,这个不是一个什么问题

This is “by design”. After you return from main, the code belongs to the library code, in this case, libc-start.c, which is not available on your machine, unless you happened to have built the libc runtime you’re using from the source. In generally, you shouldn’t need to look at code that is not yours, so you can just ignore the pop about a missing file. In your example, you can put a breakpoint on the return 0, but you shouldn’t need to step beyond that.

大概的意思就是因为缺失这个文件,所以在return from main时,会给出(善意的提示)

解决办法

1
2
3
4
5
$cd /build 
$sudo mkdir glibc-kAz5Pl
$cd glibc-kAz5Pl
$sudo wget http://ftp.gnu.org/gnu/glibc/...
$sudo tar –zxvf glibc-2.27.tar.gz

既然缺少这个文件,那就到相应的位置创建一个文件
OK解决啦
launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
// 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": "g++ 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++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}

END ~