Visual Studio CodeVS CodeWindows编程

VS Code C++ 安装和环境配置(MSVC和MinGW)

2020-03-11  本文已影响0人  LST_Jianshu

准备工作

C++项目创建

共存两种编译方式

{
    "tasks": [
        {
            "type": "shell",
            "label": "cl.exe build",
            "command": "cl.exe",
            "args": [
                //头文件路径
                "/I'D:\\Programs\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\include'",
                "/I'C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared'",
                "/I'C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt'",
                "/I'C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um'",
                "${file}",
                "/Zi", //生成调试信息
                "/EHsc", //打开异常处理
                "/Fo:${fileDirname}\\MSVC\\${fileBasenameNoExtension}.obj", //目标文件
                "/Fe:${fileDirname}\\MSVC\\${fileBasenameNoExtension}.exe", //可执行文件
                "/link", //链接标志
                //库文件路径
                "/libpath:'D:\\Programs\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\lib\\x64'",
                "/libpath:'C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\ucrt\\x64'",
                "/libpath:'C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64'"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always"
            },
            "problemMatcher": "$msCompile"
        },
        {
            "type": "shell",
            "label": "g++.exe build",
            "command": "g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\MinGW\\${fileBasenameNoExtension}.exe",
                //头文件路径
                "-I D:\\Programs\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\include",
                "-I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared",
                "-I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt",
                "-I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um",
                //库文件路径
                "-L D:\\Programs\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\lib\\x64",
                "-L C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\ucrt\\x64",
                "-L C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64"
            ],
            "options": {
                "cwd": "D:\\Programs\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ],

    "version": "2.0.0"
}
build.PNG

launch.json

{
    "version": "0.2.0",
    
    "configurations": [
        //cdb
        {
            "name": "cl.exe build and debug",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "MSVC\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false, //子进程console
            "preLaunchTask": "cl.exe build",
            "logging": {
                "moduleLoad": false
            },
        },
        //gdb
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\MinGW\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++.exe build"
        }
    ]
}

(后记:对于多源文件和方便性可以使用CMake,本文可以帮助复习一下编译工具相关的知识)

上一篇下一篇

猜你喜欢

热点阅读