当前位置:   article > 正文

C++-配置vscode_vscode-server.tar.gz

vscode-server.tar.gz

vscode配置


  • launch.json preLaunchTask和task.json中label相同

win10

  1. 下载vscode,默认安装即可
  2. 下载mingw,压缩包,因为online的.exe下载太慢,这个压缩包浏览器下载也太慢,复制链接到迅雷下载飞快。
    下载后将压缩包解压到软件安装的位置,将*\mingw64\bin*添加到环境变量即可
  3. 安装vscode插件,暂时只安装了C/C++ code runner, 修改配置File>Preferences>setting>User>Run Code configuration
    勾选以下项即可再vscode终端运行代码(linux 1.44好像没找到,需要安装code runner插件才可以)
    vscode Terminal runing
  4. 测试代码
  • test.cpp
#include <iostream>
using namespace std;
int main(){
   cout<< "Hello World!"<<endl;
   return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

运行
ctrl+alt+n or F5

  • 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
                }
            ],
        },
    ]
}
  • 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
  • 再按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"
        }
    ]
}
  • 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
  1. 程序可以运行,具体配置含义用到再了解

基本参照这个配置,建议看原文,只有tasks.json"label": "cpp.exe build active file",这样必须有,其他均一致
-2019.11.19更新,在新的电脑上这样配置task.json, 不行,参考这个,修改

"label": "g++", //和launch.json中preLaunchTask一致
"command": "D:/mingw64/bin/g++.exe",
  • 1
  • 2

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
                }
            ]
        }
    ]
}
  • 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
  • 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"]
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

F5运行OK


添加头文件路径

#include<caffe/caffe.hpp>
  • 1

出错,参考这个

  • 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
}
  • 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

实验证明,"browse"这个参数可以不配置

  • 修改task.json
"args": ["-g", "${file}", "-I", "/home/wl/software/caffe/include", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
  • 1

-I表示包含头文件路径,实验证明不要这个配置也行

  • 但是还是会抛出其他错误
	"message": "cannot open source file \"cublas_v2.h\" (dependency of \"caffe/caffe.hpp\")",
  • 1

经查阅,是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/* .
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/177776
推荐阅读
相关标签
  

闽ICP备14008679号