說明:此文章是我完全轉(zhuǎn)載的,我只是完全拷貝過來作為備份文章,,方便查看,。 在此感謝原作者,,原作者文章地址:https://blog.csdn.net/qq_43067190/article/details/82117149 環(huán)境: WIN10 64 專業(yè)版 vscode版本:1.24.1 launch.json版本:0.2.0 tasks.json版本:2.0.0 mingw-w64版本:8.1.0 配置過程: 一、 安裝vscode vscode官網(wǎng)下載安裝包直接安裝即可 二,、 vscode內(nèi)安裝C/C++ 插件 vscode內(nèi)按快捷組合鍵Ctrl+Shift+X(或如圖點擊[拓展]按鈕)打開拓展分頁,,在搜索欄輸入” C “,查找到如圖的第一個插件,安裝并重新加載之,。再推薦幾個插件,,包括彩虹括號和漢化,。
三、 安裝mingw-w64(具體安裝與環(huán)境變量配置可以查看這里) 在mingw-w64官網(wǎng)下載64位的mingw-w64離線包 https:///projects/mingw-w64/files/?source=navbar 根據(jù)系統(tǒng)選擇合適的安裝包進行下載(win10_64位選擇如圖標簽) 下載完成后出現(xiàn)安裝包 安裝該包,,在Setting 界面將Architecture選項改為x86_64,其他不變,,選擇合適的安裝路徑(默認或重新指定都可以,,路徑中不要有中文) 也可以直接下載文件壓縮包(我是下載文件壓縮包直接解壓就可以用了) 配置計算機環(huán)境變量如圖(我的解壓路徑是C:\Program Files\mingw-w64\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0,,因此環(huán)境變量這么加)
安裝完成后打開控制臺,分別輸入 g++ -v 和 gcc -v,、gdb -v 查看環(huán)境是否安裝成功(是否有當前版本號) 四、重啟電腦(重要),。 五,、配置運行環(huán)境 打開vscode,,選擇或新建一個空文件夾目錄打開作為項目目錄。 點擊“文件”按鈕,,再點擊“新建文件夾”按鈕,,并重命名為”.vscode”。 在該文件夾內(nèi),,在點擊“新建文件”按鈕,建launch.json,,settings.json,,tasks.json三個.json文件,。如圖所示。
launch.json的文件內(nèi)容如下: "preLaunchTask": "build", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "cwd": "${workspaceFolder}", "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/gdb.exe", // 這里修改GDB路徑為安裝的mingw64的bin下的gdb.exe路徑 "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing",
tasks.json的文件內(nèi)容如下: "\"${fileDirname}\\${fileBasenameNoExtension}.exe\"", "-finput-charset=UTF-8",//輸入編譯器文本編碼 默認為UTF-8 "-fexec-charset=GBK"//編譯器輸出文本編碼 自行選擇
settings.json的文件內(nèi)容如下: 用戶設(shè)置為: // Configuring tasks.json for C/C++ debugging // repo: https://gist.github.com/huihut/887d3c28db92617bd5148c20a5ff112a // Available variables which can be used inside of strings. // ${workspaceRoot}: the root folder of the team // ${file}: the current opened file // ${fileBasename}: the current opened file's basename // ${fileDirname}: the current opened file's dirname // ${fileExtname}: the current opened file's extension // ${cwd}: the current working directory of the spawned process "\"${fileDirname}\\${fileBasenameNoExtension}.exe\"" "files.autoSave": "afterDelay", "files.encoding": "utf8", "files.autoGuessEncoding": true, "explorer.confirmDragAndDrop": false, "workbench.colorTheme": "Visual Studio Dark", "team.showWelcomeMessage": false
工作區(qū)設(shè)置: "C_Cpp.errorSquiggles": "Disabled",
至此,環(huán)境配置完成,。 六、運行C代碼 新建helloworld.c文件,,鍵入或粘貼C語言的helloworld代碼,,按F5調(diào)試運行。 printf("hello world!\n\n");
代碼中system(“pause”);語句是“請按任意鍵繼續(xù)….”,,沒有此句,調(diào)試窗口將一閃就退出,。
|