VSCode配置C/C++并添加非工作區(qū)頭文件的方法
下文均在Windows環(huán)境下:
配置C/C++
按照教程安裝MinGW,并配置gcc和g++,配置方法有兩種:
1 GUI配置
在MinGW Installation Manager中選取對應(yīng)的Package,然后Installation->Apply Changes,如果失敗則多試幾次。

2 控制臺配置
配置系統(tǒng)環(huán)境變量:
1.xxx/MinGW/bin;
即安裝MinGW目錄下的bin文件夾
然后在cmd中輸入:
1.mingw-get install gcc g++ mingw32-make
添加非工作區(qū)頭文件
•Ctrl+Shift+P 。選擇c_cpp_properties.json,includePath和browse中都需要添加需要的頭文件路徑;
{
"configurations": [
{
"name": "MinGW",
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:/MinGW/bin/gcc.exe",
"includePath": [
"${workspaceFolder}",
"C:/test"
],
"defines": [],
"browse": {
"path": [
"${workspaceFolder}",
"C:/test"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
假設(shè)C:/test是非工作區(qū)頭文件路徑。
•tasks.json中添加鏈接庫,"-I"
{
"version": "2.0.0",
"command": "g++",
"args": ["-g","${file}","-I","C:/test","-o","${fileBasenameNoExtension}.exe"], // 編譯命令參數(shù)
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
gcc帶不同參數(shù)的含義:"-g"產(chǎn)生調(diào)試信息,"-c"編譯中間目標文件,"-I"指定鏈接庫,"-o"生成指定命名的可執(zhí)行文件。
知識點補充:vscode添加頭文件路徑
win+p 。選擇c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/src/linux-headers-4.15.0-36-generic/include/" //此處添加頭文件路徑,
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
總結(jié)
到此這篇關(guān)于VSCode配置C/C++并添加非工作區(qū)頭文件的方法的文章就介紹到這了,更多相關(guān)vscode 配置c++ 添加頭文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++使用JsonCpp庫操作json格式數(shù)據(jù)示例
這篇文章主要介紹了C++使用JsonCpp庫操作json格式數(shù)據(jù),結(jié)合實例形式詳細分析了JsonCpp庫的下載及C++使用JsonCpp庫對json格式數(shù)據(jù)序列化相關(guān)操作技巧,需要的朋友可以參考下2017-06-06

