vscode配置
- launch.json preLaunchTask和task.json中label相同
win10
- 下载vscode,默认安装即可
- 下载mingw,压缩包,因为online的.exe下载太慢,这个压缩包浏览器下载也太慢,复制链接到迅雷下载飞快。
下载后将压缩包解压到软件安装的位置,将*\mingw64\bin*
添加到环境变量即可 - 安装vscode插件,暂时只安装了
C/C++
code runner
, 修改配置File>Preferences>setting>User>Run Code configuration
勾选以下项即可再vscode终端运行代码(linux 1.44好像没找到,需要安装code runner插件才可以)
- 测试代码
- test.cpp
#include <iostream>
using namespace std;
int main(){
cout<< "Hello World!"<<endl;
return 0;
}
运行
ctrl+alt+n
orF5
F5
运行创建了.vscode/launch.json
修改文件
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++", //配置名称
"type": "cppdbg", //配置类型,默认
"request": "launch", //请求配置类型,launch启动,attach附加?
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", //调试程序路径
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}", //工作目录
"environment": [],
"externalConsole": true, //是否显示控制台
"MIMode": "gdb",
"miDebuggerPath": "C:/Program Files/mingw64/bin/gdb.exe", //gdb路径
"preLaunchTask": "g++", //编译g++/c++,gcc/c
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}
- 再按
F5
弹框,点击configure task, 编辑tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cpp.exe build active file",
//"command": "D:\\mingw64\\bin\\cpp.exe",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
- 程序可以运行,具体配置含义用到再了解
基本参照这个配置,建议看原文,只有tasks.json
中"label": "cpp.exe build active file",
这样必须有,其他均一致
-2019.11.19更新,在新的电脑上这样配置task.json
, 不行,参考这个,修改
"label": "g++", //和launch.json中preLaunchTask一致
"command": "D:/mingw64/bin/g++.exe",
ubuntu16.04
ctrl+alt+n
可以运行F5
并不会出现.json
配置
手动配置- 你可以在菜单栏里面选择
Terminal-->Configure Tasks
,会自动帮你生成.vscode
目录 .vscode
文件夹下新建launch.json
tasks.json
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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask":"build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
}
]
}
F5
运行OK
添加头文件路径
#include<caffe/caffe.hpp>
出错,参考这个
ctrl+shift+p
选择c/c++ config
,会创建c_cpp_properties.json
文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/wl/software/caffe/include"
],
"browse": {
"path": [
"${workspaceFolder}",
"/home/wl/software/caffe/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
实验证明,"browse"这个参数可以不配置
- 修改
task.json
"args": ["-g", "${file}", "-I", "/home/wl/software/caffe/include", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
-I
表示包含头文件路径,实验证明不要这个配置也行
- 但是还是会抛出其他错误
"message": "cannot open source file \"cublas_v2.h\" (dependency of \"caffe/caffe.hpp\")",
经查阅,是caffe有关cuda配置的,但是我的caffe明明编译的是cpu版本…
- 剩下来解决
#include<caffe/caffe.hpp>
出错问题,重开一个记录
配置win10 python选择conda 环境
vscode 运行python 脚本时,不能在终端使用conda activate env_name 激活环境
按照 https://github.com/Microsoft/vscode-python/issues/5541 在终端运行 conda init powershell
, 重启终端即可。
vscode 远程vscode-server.tar.gz 下载问题
没有配置科学上网,连接远程服务器总是出现由于vscode-server.tat.gz
而连不上
- 下载vscode-server.tar.gz
原始的下载网址为
https://update.code.visualstudio.com/commit:3b889b090b5ad5793f524b5d1d39fda662b96a2a/server-linux-x64/stable
commit
后面的一串就是你的vscode commit id 替换即可,但是上述网址打不开
一个可替代的网址是
https://vscode.cdn.azure.cn/stable/3b889b090b5ad5793f524b5d1d39fda662b96a2a/vscode-server-linux-x64.tar.gz
- 解压
在/root/.vscode-server/bin
文件夹下创建commit id
的文件夹
将vscode-server.tar.gz
移动到此文件夹下
tar -xvf vscode-server.tar.gz
再将解压的文件移动到commit id
文件夹下即可
mv vscode-server/* .