• 高效使用Vscode(C++&Python)


    1.关于vscode

    在这里插入图片描述
    下载地址: https://code.visualstudio.com/download (linux / win)
    建议:拥有一个微软账号或者github账号登录vscode来保存和更新自己的

    2.vscode常用插件安装

    在这里插入图片描述

    3.关于SSH

    什么是SSH
    一种安全的网络协议
    在这里插入图片描述
    两种连接方式

    • a. 终端连接
    • b. vscode连接(上文提到的remote插件必须装好)

    Vscode 如何进行ssh连接
    在这里插入图片描述
    在这里插入图片描述

    • Host:主机名可以自己随便定义一个名字

    文件传输(关于scp)
    下载:
    在这里插入图片描述
    从当前服务器,向ipry2.ggpu.net,用户名为root,端口号为16101的服务器传送数据到/data/yws目录下

    scp -r -P 16101   /data/yws/code root@ry2.ggpu.net:/data/yws
    
    • 1

    上传:
    在这里插入图片描述

    4.高效的快捷键和自定义设置

    4.1 快捷键

    在这里插入图片描述
    其他参考: https://betterprogramming.pub/15-useful-vscode-shortcuts-to-boost-your-productivity-415de3cb1910

    4.2 设置alias

    可以通过alias的方式,用更加简单的字符串去代表比较长的字符串。可以通过
    vim ~/.bashrc 在配置文件中 添加alias简化的命令。

    alias ll= 'ls -alF'
    alias la= 'ls -A'
    alias l= 'ls -CF'
    alias cdme= 'cd /datav/'
    alias cs= 'clear'
    alias sfm= 'du --block-size=MiB --max-depth=1 | sort -rn'
    alias sfg= 'du --block-size=GiB --max-depth=1 | sort -rn'
    alias bb = 'vim ~/.bashrc'
    alias ss = 'source ~/.bashrc'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    也可以不打开~/.bashrc直接在终端通过echo的方式写入命令,例如:
    echo alias ss= \"ls -A\" >> ~/.bashrc
    然后快捷指令生效, source ~/.bashrc

    5.高效调试配置(tasks.json 和 launch.json)

    需要配置:c_cpp_properties.json,launch.json,settings.json,tasks.json,这四个配置文件;

    在这里插入图片描述

    5.1 配置launch.json

    创建launch.json
    在这里插入图片描述
    lanuch.json文件的脚本

    • lanuch.json配置了python debug和c++ debug,实现python 和c++ 进行混编

    Python 和 c++

    {
    	"version":"0.2.0",
    	"configurations": [
    	// python debug
    	{
    		"name":"Python file",
    		"type":"python",
    		"request":"launch",
    		"program":"${file}", // 当前文件
    		//"program":"src/main.py",  // 如果指定当前目录具体的文件,介意这样写
    		"program":"src/main.py",
    		"console": "integratedTerminal",
    		"justMyCode":true  //设置false的话,你可以进入一些库的源码里面进行调试,比如说进入pytorch的一部分源码		
    	},
    	
    	// c++ debug
    	{
    	 	"name": "C++ file",
    	 	"type": "cppdbg",
    	 	"request":"launch",
    	 	"program": "${workspaceFolder}/workspace/pro", // 这里的pro指的是你要调试的文件,这里指的是cpp最终生成的可执行文件
    	 	"args": [],
    	 	"environment":[{"name":"LD_LIBRAYRY_PATH","value":"$(LD_LIBRAYRY_PATH):/mypath/to/lib/"}], //相当于直接  export LD_LIBRAYRY_PATH=$LD_LIBRAYRY_PATH:/mypath/to/lib
    		"stopAtEntry":false,
    		"cwd":"${workspaceFolder}/workspace",  //c++ 运行过程时会在这寻找依赖和其他文件(比如 图片)
    		 "externalConsole": false,
                "MIMode": "gdb",
                "miDebuggerPath": "/usr/bin/gdb",
                "environment": [
                    {
                        "name": "LD_LIBRARY_PATH", 
                        "value": "/home/yuanwushui/anaconda3/lib/python3.9/site-packages/trtpy/trt8cuda112cudnn8/lib64:/home/yuanwushui/anaconda3/lib:/home/yuanwushui/anaconda3/lib/python3.9/site-packages/trtpy/trt8cuda112cudnn8/py39:/home/yuanwushui/anaconda3/lib/python3.9/site-packages/trtpy/cpp-packages/opencv4.2/lib:/home/yuanwushui/anaconda3/lib/python3.9/site-packages/trtpy/lib:$LD_LIBRARY_PATH"
                    }
                ],
                "setupCommands": [
                    {
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
    		"preLaunchTask":"build"   //在运行launch之前先运行task.json里面的东西,因为task.json中的label是"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
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    详细参考:
    https://code.visualstudio.com/docs/editor/debugging

    5.2 配置tasks.json

    创建tasks.json

    • 按 F1
    • 选择“任务:配置任务
      在这里插入图片描述
    • 按 Enter 键,vscode 将为您创建一个示例 task.json
      在这里插入图片描述
      tasks.json文件的脚本
    "version":"2.0.0",
    "task":[
    	{
    		"label":"build",
    		"type": "shell",
    		"command":"make pro -j6"	// 这里的pro指的是你要调试的文件,这里指的是cpp最终生成的可执行文件
    	}
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    每次运行launch之前都会运行tasks (这里指的是都会编译一遍)

    5.3配置settings.json

    创建settings.json
    参见: 怎么快速打开vscode settings.json文件

    settings.json文件的脚本
    在这里插入图片描述

    • .vscode/settings.json中配置"*.cu":"cuda-cpp"可以实现cuda的语法解析

    settings.json

    {
        "files.associations": {
            "*.cpp": "cpp",
            "*.cu": "cuda-cpp",
            "deque": "cpp",
            "string": "cpp",
            "vector": "cpp",
            "*.tcc": "cpp",
            "__hash_table": "cpp",
            "__split_buffer": "cpp",
            "__tree": "cpp",
            "array": "cpp",
            "bitset": "cpp",
            "initializer_list": "cpp",
            "iterator": "cpp",
            "map": "cpp",
            "queue": "cpp",
            "random": "cpp",
            "set": "cpp",
            "stack": "cpp",
            "string_view": "cpp",
            "unordered_map": "cpp",
            "utility": "cpp",
            "__atomic": "cpp",
            "__functional_base": "cpp",
            "__functional_base_03": "cpp",
            "__tuple": "cpp",
            "algorithm": "cpp",
            "chrono": "cpp",
            "type_traits": "cpp",
            "filesystem": "cpp",
            "functional": "cpp",
            "limits": "cpp",
            "memory": "cpp",
            "ratio": "cpp",
            "tuple": "cpp",
            "istream": "cpp",
            "ostream": "cpp",
            "future": "cpp",
            "cctype": "cpp",
            "clocale": "cpp",
            "cmath": "cpp",
            "cstdarg": "cpp",
            "cstddef": "cpp",
            "cstdio": "cpp",
            "cstdlib": "cpp",
            "cstring": "cpp",
            "ctime": "cpp",
            "cwchar": "cpp",
            "cwctype": "cpp",
            "atomic": "cpp",
            "hash_map": "cpp",
            "hash_set": "cpp",
            "bit": "cpp",
            "codecvt": "cpp",
            "complex": "cpp",
            "condition_variable": "cpp",
            "cstdint": "cpp",
            "list": "cpp",
            "unordered_set": "cpp",
            "exception": "cpp",
            "memory_resource": "cpp",
            "numeric": "cpp",
            "optional": "cpp",
            "system_error": "cpp",
            "fstream": "cpp",
            "iomanip": "cpp",
            "iosfwd": "cpp",
            "iostream": "cpp",
            "mutex": "cpp",
            "new": "cpp",
            "sstream": "cpp",
            "stdexcept": "cpp",
            "streambuf": "cpp",
            "thread": "cpp",
            "cfenv": "cpp",
            "cinttypes": "cpp",
            "typeindex": "cpp",
            "typeinfo": "cpp",
            "ios": "cpp",
            "__nullptr": "cpp",
            "__bit_reference": "cpp",
            "__node_handle": "cpp",
            "__locale": "cpp",
            "variant": "cpp"
        }
    }
    
    • 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
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87

    5.4 配置c_cpp_properties.json

    在这里插入图片描述

    • 让 intelliSense engine(语法提示,自动补全)能够找到所需要的头文件

    c_cpp_properties.json

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**",
                    "/home/yuanwushui/anaconda3/lib/python3.9/site-packages/trtpy/trt8cuda112cudnn8/include/**",
                    "/home/yuanwushui/anaconda3/lib/python3.9/site-packages/trtpy/cpp-packages/opencv4.2/include/**"
                ],
                "compilerPath": "/usr/bin/gcc",
                "cStandard": "gnu11",
                "cppStandard": "gnu++11",
                "intelliSenseMode": "linux-gcc-x64"
            }
        ],
        "version": 4
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    ref:

    https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference#:~:text=includePath%20An%20include%20path%20is%20a%20folder%20that%20contains%20header%20files

    5.4 C++ Python 联合调试

    在launch中配置好python 和c++的debug配置如下
    在这里插入图片描述
    那我们如何确定我们按f5的时候是debug python 还是c++呢?
    在这里插入图片描述
    在这里插入图片描述

    可以通过上图红色箭头这个来选择debug的是Python file 还是C++ file,其中Python file 和C++ file 是在launch.json中定义的name变量的值。
    在这里插入图片描述
    同时在调试的窗格中也要选择调试的是python,还是C++:
    在这里插入图片描述

  • 相关阅读:
    iOS 16.4更新指南:问题解答与新功能一览
    javaEE飞机航班信息查询网站系统
    springboot+vue“漫画之家”在线漫画周边销售购物交流系统#毕业设计
    11 月 11 日 ROS 学习笔记——ROS 架构及概念
    ubuntu 20.04.4+uWSGI+Nginx安装部署Django+Vue的web前后端全过程记录(1)
    TreeMap排序探寻
    【秋招面经】全网最全大华前端题目总结
    RabbitMQ原理(五):消费者的可靠性
    Vue ——09、路由模式,404和路由勾子
    python画图
  • 原文地址:https://blog.csdn.net/weixin_38346042/article/details/127288535