VSCode配置记录

VSCode

VSCode 安装

本体安装

VSCode 官网下载安装即可

如果是重新安装需要卸载后清空以下两个文件夹方可保证卸载干净

  • C:\Users$用户名\.vscode
  • C:\Users$用户名\AppData\Roaming\Code

汉化

安装此插件即可

057

配置C/C++环境

之前配的初级版就不说了,直接说最近配的完全体吧。主要是最近有个问题需要用到 32 位的编译器所以重新完善了一下配置。

MinGW-W64安装与配置

MinGW 的全称是:Minimalist GNU on Windows ,实际上是将 gcc(c/c++编译器)移植到了 Windows 平台下。

sourceforge 的 mingw 项目上下载即可,注意版本的选择:

058
  • 莫要用在线版本,不用点魔法的话下不动的
  • 系统版本:选 x86_64
    • x86_64 指 64 位的操作系统,x 代表不确定,可以是 386、486、586、686
    • i686 支持 32 位的操作系统,i 代表 intel 系列的 CPU,pentun II 以后的 Intel 系列 CPU 以及 K7 以后的 CPU 都属于686 等级
  • 线程模型:莫得什么区别
    • posix:启用 C++11/C11 多线程功能。 依赖于 libwinpthreads,即使你不直接调用 API,也将分发给 winpthreads。 使用应用程序分发一个 DLL 没有什么问题。
    • win32:没有 C++11 多线程功能。
  • 异常处理模型 :选 sjlj
    • seh:Borland 公司出的,巨硬买了,支持 64 位系统,调用系统机制处理异常
    • sjlj:全称是 SetJump LongJump,支持 32/64 位系统,缺点是运行速度稍慢
    • dwarf:因为带调试信息所以比一般的包尺寸大,比 sjlj 性能好,但是仅支持 32 位系统

下载后解压,并将 bin 目录添加进环境变量的 PATH 中即可。

安装及配置相关插件

安装插件

安装 C/C++ 插件以及 Coder Runner 插件即可,安装后需重启 VSCode

059 060

配置文件

需在工作目录下建立 .vscode 文件夹并将以下配置文件置于该文件夹内:

061
launch.json

该文件为 VSCode 的调试的配置

  • configurations 数组中每个值都是一个运行和调试配置项
  • name 即为该运行和调试配置项显示的名称
  • program 为被调试的 exe 文件
  • externalConsole 为 true 则启动控制台
  • miDebuggerPath 是调试程序路径,即 gdb.exe 的路径。如果要调试 32 位的程序则需要另外下载32位版本的gdb,下载之后重命名为 gdb32.exe 保存在原 gbd.exe 相同的文件夹下即可。
  • preLaunchTask 是调试前执行的任务,需要与 task.json 中的 label 对应
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++_Run_64",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW_W64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build & run file_64"
        },
        {
            "name": "C/C++_Debug_64",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW_W64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build & debug file_64"
        },
        {
            "name": "C/C++_Run_32",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW_W64\\mingw64\\bin\\gdb32.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build & run file_32"
        },
        {
            "name": "C/C++_Debug_32",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW_W64\\mingw64\\bin\\gdb32.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build & debug file_32"
        }
    ]
}
tasks.json

该文件为会话前执行的动作的配置

  • tasks 数组中每个值都是一个配置
  • label 是每个配置的标签,可在launch.json中使用
  • command 是指令前缀
  • args 是指令各个选项
    • -o 指定可执行文件的名称,这里我把 exe 文件都放到 exe 文件夹里了
    • -g 是 gdb 选项,需要调试则添加
    • -m32 可指定编译位数,默认是 64 位
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build & run file_64",
            "type": "shell",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "build & debug file_64",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "build & run file_32",
            "type": "shell",
            "command": "g++",
            "args": [
                "-m32",
                "${file}",
                "-o",
                "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "build & debug file_32",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "-m32",
                "${file}",
                "-o",
                "${workspaceFolder}\\exe\\${fileBasenameNoExtension}.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

c_cpp_properties.json

这个文件主要是配置一下 includePath 防止出现头文件错误

includePath 可以通过以下命令获取:

gcc -v -E -x c++ -
062
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\MinGW_W64\\mingw64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++",
                "C:\\MinGW_W64\\mingw64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\\x86_64-w64-mingw32",
                "C:\\MinGW_W64\\mingw64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\\backward",
                "C:\\MinGW_W64\\mingw64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include",
                "C:\\MinGW_W64\\mingw64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include-fixed",
                "C:\\MinGW_W64\\mingw64\\bin\\..\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\..\\..\\..\\..\\x86_64-w64-mingw32\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\MinGW_W64\\mingw64\\bin\\gcc.exe",
            "intelliSenseMode": "windows-gcc-x86",
            "cStandard": "c99",
            "cppStandard": "c++14"
        }
    ],
    "version": 4
}
settings.json

这个主要是配置一下编码当前工作目录的编码格式,不是 gbk 中文会乱码,隔壁 Python 则需要 UTF-8。另外就是个人喜好,设置大括号不换行。

{
    "files.encoding": "gbk",
    "C_Cpp.clang_format_style": "{ BasedOnStyle: Chromium, IndentWidth: 4}"
}

配置Python环境

安装插件

063

写配置文件

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "python": "C:\\Software\\Python\\python.exe",
            "console": "externalTerminal"
        }
    ]
}

settings.json

{
    "python.pythonPath": "C:\\Software\\Python\\python.exe",
    "terminal.integrated.env.windows": {"PYTHONPATH":"${workspaceFolder}/"},
    "python.linting.pylintArgs": ["--generate-members"]
}

配置HTML以及JavaScript

安装插件

对于HTML以及JavaScript主要还是依赖于浏览器,所以仅需安装Liver Server插件实现从浏览器打开

064

当然,也可以使用node.js去运行JS代码,关于node.js的安装参见前文。

写配置文件

使用node.js运行则是需要写配置文件的

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "JavaScript: node.js",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\${fileBasenameNoExtension}.js"
        }
    ]
}
posted @   AncilunKiang  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示