vscode+wsl+mingw编译调试配置样例

vscode使用wsl(ubuntu)编译调试样例,使用mingw编译调试样例

1.安装vscode及插件如下

可以参考使用WSL+VSCode快速C++入门_wsl c++ setting.json_逗神大人的博客-CSDN博客

2.安装wsl和mingw

mingw从官方下载较慢,可以从下面下载

https://download.csdn.net/download/qjm1995/11094533

3.使用wsl编译和调试

配置文件详细如下:

c_cpp_properties.json

{
    "configurations": [{
        "name": "WSL",
        "intelliSenseMode": "gcc-x64",
        "compilerPath": "/usr/bin/g++",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [],
        "cStandard": "c11",
        "cppStandard": "c++17"
    }],
    "version": 4
  }

launch.json

{
    "version": "0.2.0",
    "configurations": [{
        "name": "hello Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "/mnt/d/vscode_work/wsl_hello/hello",
        "args": [],
        "stopAtEntry": false,
        "cwd": "/mnt/d/vscode_work/wsl_hello",
        "environment": [],
        "externalConsole": true,
        "windows": {
            "MIMode": "gdb",
            "setupCommands": [{
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }]
        },
        "pipeTransport": {
            "pipeCwd": "",
            "pipeProgram": "c:\\windows\\sysnative\\bash.exe",
            "pipeArgs": ["-c"],
            "debuggerPath": "/usr/bin/gdb",
        },
        "sourceFileMap": {
            "/mnt/d": "d:\\"
        }
    }]
  }

settings.json

{
    "terminal.external.windowsExec": "C:\\WINDOWS\\System32\\bash.exe",
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"
    "files.associations": {
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "numeric": "cpp"
    }
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "process",
            "command": "bash.exe",
            "args": [
                "-c",
                "scons"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
  }

SConstruct

env=Environment(CCFLAGS = ['-g','-std=c++11','-Wall']) 
env.Program('hello', Glob('*.cpp'), LIBS = ['m'], LIBPATH = ['/usr/lib'])

4.使用mingw编译和调试

配置文件详细如下:

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}",
                "D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\MinGW\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json


{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "hello Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/hello.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build hello"
        }
    ]
}

settings.json

{
    "files.associations": {
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "numeric": "cpp"
    }
}

tasks.json


{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hello",
            "type": "shell",
            "command": "g++",
            "args": [
                "*.cpp",
                "-g",
                "-o",
                "hello.exe",
                "-std=c++11",
                "-Wall",
                "-lm",
                "-L.",
                "-I."
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

PS:

https://www.youtube.com/watch?v=ZFtrZh20CAc

当谈到美化和搭建Linux开发环境时, VS Code,WSL和Windows Terminal都是非常有用的工具。 首先,VS Code是一款流行的开源代码编辑器,可通过安装各种插件进行美化。你可以选择喜欢的主题和语法高亮方案,以配合你的个人喜好。 其次,WSL(Windows Subsystem for Linux)是一种在Windows上运行Linux二进制文件的兼容层。通过安装WSL,你可以在Windows中使用真正的Linux发行版,如Ubuntu或Debian。这样,你就可以在Windows系统中体验和开发Linux环境下的应用程序。 最后,Windows Terminal是Windows新的命令行终端。它支持多个选项卡以及各种自定义设置,如调整配色方案、字体大小和字体类型等。你可以使用Windows Terminal将多个终端会话放置在一个窗口中,从而提高工作效率。 要搭建Linux开发环境,首先你需要安装WSL以及喜欢的Linux发行版。然后,你可以通过安装VS Code插件和扩展来优化你的开发体验。安装一些常用的扩展,如Python、C++或Node.js,以根据你的需求进行开发。 当你需要在Windows环境中执行Linux命令时,你可以打开Windows Terminal,并选择WSL作为默认终端。这样,你就可以通过Windows Terminal运行和管理你的Linux环境。 总结起来,VS Code,WSL和Windows Terminal是一些功能强大且易于使用的工具,它们可以帮助你美化和搭建Linux开发环境。使用这些工具,你可以在Windows中轻松进行Linux开发,并以最佳方式执行命令和编辑代码。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值