您好,登錄后才能下訂單哦!
下文均在Windows環境下:
配置C/C++
按照教程安裝MinGW,并配置gcc和g++,配置方法有兩種:
1 GUI配置
在MinGW Installation Manager中選取對應的Package,然后Installation->Apply Changes,如果失敗則多試幾次。
2 控制臺配置
配置系統環境變量:
1.xxx/MinGW/bin;
即安裝MinGW目錄下的bin文件夾
然后在cmd中輸入:
1.mingw-get install gcc g++ mingw32-make
添加非工作區頭文件
•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 }
假設C:/test是非工作區頭文件路徑。
•tasks.json中添加鏈接庫,"-I"
{ "version": "2.0.0", "command": "g++", "args": ["-g","${file}","-I","C:/test","-o","${fileBasenameNoExtension}.exe"], // 編譯命令參數 "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帶不同參數的含義:"-g"產生調試信息,"-c"編譯中間目標文件,"-I"指定鏈接庫,"-o"生成指定命名的可執行文件。
知識點補充: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 }
總結
到此這篇關于VSCode配置C/C++并添加非工作區頭文件的方法的文章就介紹到這了,更多相關vscode 配置c++ 添加頭文件內容請搜索億速云以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持億速云!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。