vs code 調試C/C++代碼時,不能有中文路徑


調試C/C++ 添加3個配置

//文件名:settings.json
{
    "files.defaultLanguage": "cpp",    // ctrl+N新建文件后默認的語言
    "code-runner.runInTerminal": true, // 設置成false會在“輸出”中輸出,無法交互
    "code-runner.executorMap": {
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -std=c11 && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -std=c++17 && $dir$fileNameWithoutExt"
    }, // 設置code runner的命令行
    "code-runner.saveFileBeforeRun": true, // run code前保存
    "code-runner.preserveFocus": true,     // 若為false,run code后光標會聚焦到終端上。如果需要頻繁輸入數據可設為false
    "code-runner.clearPreviousOutput": false, // 格式化時調整include的順序(按字母排序)
    "C_Cpp.intelliSenseEngine": "Default", // 可以為Default或Tag Parser,后者較老,功能較簡單。具體差別參考cpptools插件文檔
    "C_Cpp.errorSquiggles": "Disabled", // 因為有clang的lint,所以關掉
    "editor.formatOnType": true, // 輸入時就進行格式化,默認觸發字符較少,分號可以觸發
    "editor.snippetSuggestions": "top", // snippets代碼優先顯示補全

    // 控制c語言靜態檢測的參數
    "clang.cflags": [
        "-std=c11",
        "-Wall"
    ],

    // 控制c++靜態檢測時的參數
    "clang.cxxflags": [
        "-std=c++17",
        "-Wall"
    ],
    "clang.completion.enable": false, // 效果稍好,但太卡,故關掉
    "files.exclude": {
        "**/.DS_Store": false,
        "**/*.exe": true,
        "**/.vscode": false
    },
    "files.associations": {
        "*.md": "markdown",
        "*.h": "c",
        "*.C": "c",
        "stdlib.h": "c",
        "mt_allocator.h": "c",
        "malloc.h": "c",
        "unistd.h": "c",
        "dirent.h": "c",
        "stdio.h": "c",
        "dir.h": "c",
        "stdbool.h": "c",
        "cstdbool": "c",
        "c++config.h": "c",
        "iostream": "cpp"
    },
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.unitTest.pyTestArgs": [
        "Python"
    ],
    "python.unitTest.unittestEnabled": false,
    "python.unitTest.nosetestsEnabled": false,
    "python.unitTest.pyTestEnabled": true,
    "python.formatting.provider": "yapf",
    "svn.ignoreMissingSvnWarning": true,
    "C_Cpp.clang_format_style": ""
}

 

文件支持:

//文件名:launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",     /* 配置名稱,將會在啟動配置的下拉菜單中顯示*/
            "type": "cppdbg",           /* 配置類型,這里只能為cppdbg*/
            "request": "launch",        /* 請求配置類型,可以為launch(啟動)或attach(附加)*/
            "targetArchitecture": "x86",/* 生成目標程序架構*/
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",      /* 將要進行調試的程序的路徑*/
            "miDebuggerPath": "C:/Qt/Qt5.9.8/Tools/mingw530_32/bin/gdb.exe", /* 調試器路徑*/
            "args": [],                 /* 程序調試時傳遞給程序的命令行參數,一般設為空即可*/
            "stopAtEntry": true,        /* 設為true時程序將暫停在程序入口處,我一般設置為true*/
            "cwd": "${workspaceFolder}",/* 調試程序時的工作目錄*/
            "environment": [],
            "externalConsole": true,    /* 調試時是否顯示控制台窗口,一般設置為true顯示控制台*/
            "internalConsoleOptions": "neverOpen", /* 如果不設為neverOpen,調試時會跳到“調試控制台”選項卡*/
            "MIMode": "gdb",            /* 指定連接的調試器,可以為gdb或lldb。但目前lldb在windows下沒有預編譯好的版本*/
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "Compile" /* 調試會話開始前執行的任務,一般為編譯程序。與tasks.json的label相對應*/
        }
    ]
}
// 文件名:tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile",
            "command": "gcc",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-g",
                "-Wall",
                "-static-libgcc",
                //"-std=c++17"
            ],
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            }
        }
    ]
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM