VSCode新增標頭檔案(C/C++)的實現示例
阿新 • • 發佈:2020-08-10
使用VSCode編譯C/C++時,會存在找不到標頭檔案的情況這時候需要設定兩個地方:
1.c_cpp_properites.json
2.task.json
以下是我修改的對應的檔案
{ "configurations": [ { "name": "Win32","includePath": [ "${workspaceFolder}/**","${workspaceRoot}","xxx/include" ],"browse": { "path": [ "${workspaceRoot}","xxx/lib" ] },"defines": [ "_DEBUG","UNICODE","_UNICODE" ],"compilerPath": "xxx/gcc.exe","cStandard": "c11","cppStandard": "c++17","intelliSenseMode": "gcc-x64" } ],"version": 4 }
{ "version": "2.0.0","command": "g++","args": ["-g","${file}","-Lxxx/lib","-Ixxx/include","-o","${fileBasenameNoExtension}.exe"],// 編譯命令引數,新增-L,-I選項 "problemMatcher": { "owner": "cpp","fileLocation": ["relative","${workspaceRoot}"],"pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$","file": 1,"line": 2,"column": 3,"severity": 4,"message": 5 } } }
附加上launch.json,參考網上的,連結找不到了,感謝原作者。
{ "version": "0.2.0","configurations": [ { "name": "(gdb) Launch",// 配置名稱,將會在啟動配置的下拉選單中顯示 "type": "cppdbg",// 配置型別,這裡只能為cppdbg "request": "launch",// 請求配置型別,可以為launch(啟動)或attach(附加) "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",// 將要進行除錯的程式的路徑 "args": [],// 程式除錯時傳遞給程式的命令列引數,一般設為空即可 "stopAtEntry": false,// 設為true時程式將暫停在程式入口處,一般設定為false "cwd": "${workspaceRoot}",// 除錯程式時的工作目錄,一般為${workspaceRoot}即程式碼所在目錄 "environment": [],"externalConsole": true,// 除錯時是否顯示控制檯視窗,一般設定為true顯示控制檯 "MIMode": "gdb","miDebuggerPath": "xxx\\gdb.exe",// miDebugger的路徑,注意這裡要與MinGw的路徑對應 "preLaunchTask": "g++",// 除錯會話開始前執行的任務,一般為編譯程式,c++為g++,c為gcc "setupCommands": [ { "description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true } ] } ] }
vscode 新增標頭檔案路徑的方法
配置IntelliSense
擴充套件程式會根據當前系統環境配置基本資訊,因此有可能配置不完整,這時需要通過生成c_cpp_properties.json檔案來配置缺少的資訊:
ctrl+shift+P開啟Command Palette,執行C/Cpp: Edit configurations...生成c_cpp_properties.json:
"includePath": [ "${workspaceFolder}/**","D:\\ite_sdk\\sdk\\**","D:\\ite_sdk\\openrtos\\**","C:\\ITEGCC\\*"
構建應用程式
如果要構建應用程式,則需要生成tasks.json檔案:
Ctrl+Shift+P -> Tasks: Configure Tasks… -> Create tasks.json file from templates -> Others.
到此這篇關於VSCode新增標頭檔案(C/C++)的實現示例的文章就介紹到這了,更多相關VSCode新增標頭檔案內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!