# VSCode 配置
- Visual Studio Code 下载地址:https://code.visualstudio.com/download
- VS Code 建议安装插件列表:
- 中文菜单:
- MS-CEINTL.vscode-language-pack-zh-hans
- SSH 远程开发:
- ms-vscode-remote.remote-ssh
- ms-vscode-remote.remote-ssh-edit
- ms-vscode.remote-explorer
- C++ 开发
- python 开发
- 代码补全
# SSH 连接远端 Linux 主机
点击 VSCode 左下角的 >< 符号,创建一个新的 SSH 连接,输入连接命令即可打开新的窗口,然后正确输入密码即可连接到远端的 Linux 主机
# Linux 配置
# 安装 miniconda
| wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh |
| bash Miniconda3-py39_4.12.0-Linux-x86_64.sh |
默认会安装在用户目录下,保持默认即可
安装完成后用 source .bashrc
刷新配置文件,即可看见命令行前面有个 (base)
前缀,即安装成功
# 安装 opencv
如果用 conda install opencv
命令安装成功后,import cv2 可能还会报错,缺少一个依赖,运行下列命令安装依赖
| sudo apt update |
| sudo apt install libgl1-mesa-glx |
如果用 pip 安装 mediapipe 速度慢,可以在用户目录下创建 .pip/pip.conf
文件,然后配置如下内容
| [global] |
| index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ |
| [install] |
| trusted-host = pypi.tuna.tsinghua.edu.cn |
然后重启命令行,再次用 pip install mediapipe
即可满速
# 安装 g++
| sudo apt update |
| sudo apt install build-essential |
| which g++ |
| gcc --version |
这个命令将会安装一系列软件包,包括 gcc,g++, 和 make
# 安装 gdb
| sudo apt update |
| sudo apt install gdb |
# 测试 Python
| |
| |
| |
| sum = 0; |
| for i in range(5): |
| sum += i |
| |
| |
| print(sum); |
debuger 配置.vscode 下 launch.json 添加
| { |
| |
| |
| |
| "version": "0.2.0", |
| "configurations": [ |
| { |
| "name": "Python: Current File", |
| "type": "python", |
| "request": "launch", |
| "program": "${file}", |
| "console": "integratedTerminal", |
| "justMyCode": true |
| } |
| ] |
| } |
# 测试 C++
| #include <iostream> |
| using namespace std; |
| |
| int main(){ |
| |
| |
| int sum {0}; |
| for (int i {0}; i < 5; i++){ |
| sum += i; |
| } |
| |
| cout << sum << endl; |
| return 0; |
| |
| } |
- 方法一:用 g++ main.cpp -o main 生成可执行文件
- 方法二:在.vscode 先添加 tasks.json
| { |
| "version": "2.0.0", |
| "tasks": [ |
| { |
| "type": "cppbuild", |
| "label": "C/C++: g++ 生成活动文件", |
| "command": "/usr/bin/g++", |
| "args": [ |
| "-fdiagnostics-color=always", |
| "-g", |
| "-Wall", |
| "-std=c++14", |
| "${file}", |
| |
| "-o", |
| "${workspaceFolder}/release/${fileBasenameNoExtension}" |
| ], |
| "options": { |
| "cwd": "${fileDirname}" |
| }, |
| "problemMatcher": [ |
| "$gcc" |
| ], |
| "group": { |
| "kind": "build", |
| "isDefault": true |
| }, |
| "detail": "编译器: /usr/bin/g++" |
| } |
| ] |
| } |
需要 debuger,launch.json 修改为:
| { |
| |
| |
| |
| "version": "0.2.0", |
| "configurations": [ |
| { |
| "name": "C++ 调试 (gdb) Launch", |
| "type": "cppdbg", |
| "request": "launch", |
| "program": "${workspaceFolder}/release/${fileBasenameNoExtension}", |
| "args": [], |
| "stopAtEntry": false, |
| "cwd": "${fileDirname}", |
| "environment": [], |
| "externalConsole": false, |
| "MIMode": "gdb", |
| "setupCommands": [ |
| { |
| "description": "Enable pretty-printing for gdb", |
| "text": "-enable-pretty-printing", |
| "ignoreFailures": true |
| }, |
| { |
| "description": "Set Disassembly Flavor to Intel", |
| "text": "-gdb-set disassembly-flavor intel", |
| "ignoreFailures": true |
| } |
| ], |
| "preLaunchTask": "C/C++: g++ 生成活动文件" |
| }, |
| { |
| "name": "Python: Current File", |
| "type": "python", |
| "request": "launch", |
| "program": "${file}", |
| "console": "integratedTerminal", |
| "justMyCode": true |
| } |
| ] |
| } |
# VSCode 中变量解释
${workspaceFolder}
: 表示当前 workspace 文件夹路径,也即 /home/Coding/Test${workspaceRootFolderName}
: 表示 workspace 的文件夹名,也即 Test${file}
: 文件自身的绝对路径,也即 /home/Coding/Test/.vscode/tasks.json${relativeFile}
: 文件在 workspace 中的路径,也即.vscode/tasks.json${fileBasenameNoExtension}
: 当前文件的文件名,不带后缀,也即 tasks${fileBasename}
: 当前文件的文件名,tasks.json${fileDirname}
: 文件所在的文件夹路径,也即 /home/Coding/Test/.vscode${fileExtname}
: 当前文件的后缀,也即.json${lineNumber}
: 当前文件光标所在的行号${env:PATH}
: 系统中的环境变量
# 参考链接
- Ubuntu :20.04 上安装 gcc/g++7.5
- vscode error: Please specify the "MIDebuggerPath" option