VSCode添加頭文件(C/C++)的實現(xiàn)示例
使用VSCode編譯C/C++時,會存在找不到頭文件的情況這時候需要設(shè)置兩個地方:
1.c_cpp_properites.json
2.task.json
以下是我修改的對應(yīng)的文件
{
"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"], // 編譯命令參數(shù),添加-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,參考網(wǎng)上的,鏈接找不到了,感謝原作者。
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名稱,將會在啟動配置的下拉菜單中顯示
"type": "cppdbg", // 配置類型,這里只能為cppdbg
"request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加)
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",// 將要進行調(diào)試的程序的路徑
"args": [], // 程序調(diào)試時傳遞給程序的命令行參數(shù),一般設(shè)為空即可
"stopAtEntry": false, // 設(shè)為true時程序?qū)和T诔绦蛉肟谔?,一般設(shè)置為false
"cwd": "${workspaceRoot}",// 調(diào)試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄
"environment": [],
"externalConsole": true,// 調(diào)試時是否顯示控制臺窗口,一般設(shè)置為true顯示控制臺
"MIMode": "gdb",
"miDebuggerPath": "xxx\\gdb.exe",// miDebugger的路徑,注意這里要與MinGw的路徑對應(yīng)
"preLaunchTask": "g++", // 調(diào)試會話開始前執(zhí)行的任務(wù),一般為編譯程序,c++為g++, c為gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
vscode 添加頭文件路徑的方法
配置IntelliSense
擴展程序會根據(jù)當前系統(tǒng)環(huán)境配置基本信息,因此有可能配置不完整,這時需要通過生成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\\*"
構(gòu)建應(yīng)用程序
如果要構(gòu)建應(yīng)用程序,則需要生成tasks.json文件:
Ctrl+Shift+P -> Tasks: Configure Tasks… -> Create tasks.json file from templates -> Others.
到此這篇關(guān)于VSCode添加頭文件(C/C++)的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)VSCode添加頭文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用C++中string實現(xiàn)任意長度的正小數(shù)、整數(shù)之間加減法方法實例
這篇文章主要介紹了利用C++中string函數(shù)實現(xiàn)任意長度的正小數(shù)、整數(shù)之間加減法方法實例,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。2017-06-06
C++實現(xiàn)LeetCode(205.同構(gòu)字符串)
這篇文章主要介紹了C++實現(xiàn)LeetCode(205.同構(gòu)字符串),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-07-07

