VS Code配置C/C++
VS Code 配置C/C++
? 準備工作
Mingw-w64下載,在vscode中,點擊幫助?文檔,進入如下界面。
在左側選擇C++?Mingw-w64 onWindows,進入如下界面。可以參考文檔進行配置。
點擊文檔中的mingw-w64鏈接進入如下界面。
點擊黃色區域鏈接進入到里面,再點擊下圖中的文字,進入到下載界面,下載即可。
將其自定義安裝(我的安裝在了mingw文件夾下),記住配置其路徑,D:\mingw\mingw64\bin。
? 擴展vscode插件,如下。
? .json文件配置,C/C++需要三個配置文件。
? c_cpp_properties.json
? tasks.json
? launch.json
可以參看文檔的配置,也可以根據自己的情況設置。
對于配置文檔的一些介紹:
對于launch.json文件,“configurations”: [],中括號里是書寫配置信息的,每一個配置信息,由一個{}包括, {}由逗號分隔,每個配置都會在如下圖的位置顯示出來,便于調用:
對于每一個{}包含的配置的具體項介紹如下:
{"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的值可以人為設定,會在上述位置顯示,便于區分,而"preLaunchTask": "C++ Run"這個的值,則對于tasks.json中的一個任務,其值必須和label的值對應,如下:
{"label": "C++ Run","type": "shell","command": "g++","args": ["-o","${fileBasenameNoExtension}","${file}"],"group": {"kind": "build","isDefault": true}可以設置多對上述的對應關系,用于不同語言的編譯調試。
下面是我的這幾個文件的具體配置:
? c_cpp_properties.json
? launch.json
{// 使用 IntelliSense 了解相關屬性。 // 懸停以查看現有屬性的描述。// 欲了解更多信息,請訪問: 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
總結
以上是生活随笔為你收集整理的VS Code配置C/C++的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【操作系统复习】操作系统的特征
- 下一篇: 数据结构——堆栈的C++实现