VS Code配置C/C++
VS Code 配置C/C++
? 準(zhǔn)備工作
 Mingw-w64下載,在vscode中,點(diǎn)擊幫助?文檔,進(jìn)入如下界面。
在左側(cè)選擇C++?Mingw-w64 onWindows,進(jìn)入如下界面。可以參考文檔進(jìn)行配置。
 
點(diǎn)擊文檔中的mingw-w64鏈接進(jìn)入如下界面。
 
點(diǎn)擊黃色區(qū)域鏈接進(jìn)入到里面,再點(diǎn)擊下圖中的文字,進(jìn)入到下載界面,下載即可。
 
將其自定義安裝(我的安裝在了mingw文件夾下),記住配置其路徑,D:\mingw\mingw64\bin。
? 擴(kuò)展vscode插件,如下。
 
? .json文件配置,C/C++需要三個(gè)配置文件。
 ? c_cpp_properties.json
 ? tasks.json
 ? launch.json
 可以參看文檔的配置,也可以根據(jù)自己的情況設(shè)置。
對(duì)于配置文檔的一些介紹:
 對(duì)于launch.json文件,“configurations”: [],中括號(hào)里是書(shū)寫(xiě)配置信息的,每一個(gè)配置信息,由一個(gè){}包括, {}由逗號(hào)分隔,每個(gè)配置都會(huì)在如下圖的位置顯示出來(lái),便于調(diào)用:
 
對(duì)于每一個(gè){}包含的配置的具體項(xiàng)介紹如下:
{"name": "C++ Run(minGW64)","type": "cppdbg","request": "launch","program": "${workspaceFolder}/${fileBasenameNoExtension}.exe","MIMode": "gdb","miDebuggerPath": "D:/mingw/mingw64/bin/gdb.exe","args": [],"stopAtEntry": false,"environment": [],"cwd": "${workspaceRoot}","externalConsole": false,"preLaunchTask": "C++ Run","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": false}]},Name的值可以人為設(shè)定,會(huì)在上述位置顯示,便于區(qū)分,而"preLaunchTask": "C++ Run"這個(gè)的值,則對(duì)于tasks.json中的一個(gè)任務(wù),其值必須和label的值對(duì)應(yīng),如下:
{"label": "C++ Run","type": "shell","command": "g++","args": ["-o","${fileBasenameNoExtension}","${file}"],"group": {"kind": "build","isDefault": true}可以設(shè)置多對(duì)上述的對(duì)應(yīng)關(guān)系,用于不同語(yǔ)言的編譯調(diào)試。
下面是我的這幾個(gè)文件的具體配置:
 ? c_cpp_properties.json
? launch.json
{// 使用 IntelliSense 了解相關(guān)屬性。 // 懸停以查看現(xiàn)有屬性的描述。// 欲了解更多信息,請(qǐng)?jiān)L問(wèn): https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"type": "java","name": "CodeLens (Launch) - DigitalImage","request": "launch","mainClass": "app.DigitalImage","projectName": "main"},{"name": "C++ Run(minGW64)","type": "cppdbg","request": "launch","program": "${workspaceFolder}/${fileBasenameNoExtension}.exe","MIMode": "gdb","miDebuggerPath": "D:/mingw/mingw64/bin/gdb.exe","args": [],"stopAtEntry": false,"environment": [],"cwd": "${workspaceRoot}","externalConsole": false,"preLaunchTask": "C++ Run","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": false}]},{"name": "C++ Debug(minGW64)","type": "cppdbg","request": "launch","program": "${workspaceFolder}/${fileBasenameNoExtension}.exe","MIMode": "gdb","miDebuggerPath": "D:/mingw/mingw64/bin/gdb.exe","args": [],"stopAtEntry": false,"environment": [],"cwd": "${workspaceRoot}","externalConsole": true,"preLaunchTask": "C++ Debug","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": false}]},{"name": "C Run(minGW64)","type": "cppdbg","request": "launch","program": "${workspaceFolder}/${fileBasenameNoExtension}.exe","MIMode": "gdb","miDebuggerPath": "D:/mingw/mingw64/bin/gdb.exe","args": [],"stopAtEntry": false,"environment": [],"cwd": "${workspaceRoot}","externalConsole": true,"preLaunchTask": "C Run","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": false}]},{"name": "C Debug(minGW64)","type": "cppdbg","request": "launch","program": "${workspaceFolder}/${fileBasenameNoExtension}.exe","MIMode": "gdb","miDebuggerPath": "D:/mingw/mingw64/bin/gdb.exe","args": [],"stopAtEntry": false,"environment": [],"cwd": "${workspaceRoot}","externalConsole": true,"preLaunchTask": "C Debug","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": false}]}] }? tasks.json
{"version": "2.0.0","tasks": [//C++ Run Tasks{"label": "C++ Run","type": "shell","command": "g++","args": ["-o","${fileBasenameNoExtension}","${file}"],"group": {"kind": "build","isDefault": true}},//C++ Debug Tasks{"label": "C++ Debug","type": "shell","command": "g++","args": ["-g","-o", "${fileBasenameNoExtension}","${file}"],"group": {"kind": "build","isDefault": true}},//C Run Tasks{"label": "C Run","type": "shell","command": "gcc","args": ["-o","${fileBasenameNoExtension}","${file}"],"group": {"kind": "build","isDefault": true}},//C Debug Tasks{"label": "C Debug","type": "shell","command": "gcc","args": ["-g","-o", "${fileBasenameNoExtension}","${file}"],"group": {"kind": "build","isDefault": true}}] }參考鏈接:
 https://www.cnblogs.com/TAMING/p/8560253.html
 https://www.cnblogs.com/zhuzhenwei918/p/9057289.html
 https://www.cnblogs.com/wanghao-boke/p/12076302.html
 https://www.cnblogs.com/jpfss/p/10333911.html
總結(jié)
以上是生活随笔為你收集整理的VS Code配置C/C++的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 【操作系统复习】操作系统的特征
- 下一篇: 图像处理理论-颜色模式
