這篇文章主要介紹了vscode怎么配置c語言編譯環(huán)境,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
在康平等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需定制設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè),康平網(wǎng)站建設(shè)費用合理。一、下載MinGW-W64 GCC-8.1.0編譯器(本文安裝 x86_64-win32-seh)
二、環(huán)境配置
打開你的mingw-w64安裝目錄,我是默認安裝的在C:\Program Files (x86),里面的MinGW-W64就是安裝的編譯器了,將里面的bin文件夾加入路徑,我的就是C:\Program Files (x86)\mingw64\bin,將這個加入路徑即可。
路徑加入方法:
加入后,建議重啟一下電腦。
三、安裝VSCode cpp相關(guān)的插件
c++插件
重啟vscode軟件。
四、配置c++的.vscode文件
在你寫代碼的地方新建文件夾并在里面新建一個文件夾,然后在文件夾里面創(chuàng)建一個.vscode文件夾
然后在.vscode文件夾里面創(chuàng)建如上圖所示的四個文件,文件名如下:
c_cpp_properties.json
launch.json
tasks.json
請根據(jù)安裝的位置來修改文件路徑(如果跟我一樣可以不要修改)
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", // 配置名稱,將會在啟動配置的下拉菜單中顯示 "type": "cppdbg", // 配置類型,這里只能為cppdbg "request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加) "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 將要進行調(diào)試的程序的路徑 "args": [], // 程序調(diào)試時傳遞給程序的命令行參數(shù),一般設(shè)為空即可 "stopAtEntry": false, // 設(shè)為true時程序?qū)和T诔绦蛉肟谔?,一般設(shè)置為false "cwd": "${workspaceFolder}", // 調(diào)試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄 workspaceRoot已被棄用,現(xiàn)改為workspaceFolder "environment": [], "externalConsole": true, // 調(diào)試時是否顯示控制臺窗口,一般設(shè)置為true顯示控制臺 "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/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": false } ] } ] }
tasks.json
如果遇到找不到文件 比如這樣:
把 "${workspaceFolder}"替換為 "\\"或 "http://"
{ "version": "2.0.0", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileBasenameNoExtension}.exe" ], // 編譯命令參數(shù) "problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "${workspaceFolder}" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } }
c_cpp_properties.json
"includepath"設(shè)置問題 路徑獲取獲取方法為:cmd——》gcc -v -E -x c++ -
如果第一種出錯請使用第二種
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "C:/Program Files (x86)/mingw64/include/**", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=6", "__cdecl=__attribute__((__cdecl__))" ], "intelliSenseMode": "msvc-x64", "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "path": [ "${workspaceRoot}", "C:/Program Files (x86)/mingw64/include/**", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ] } } ], "version": 4 }
第二種
{ "configurations": [ { "name": "Win32", "includePath": [ "C:/Program Files (x86)/mingw64/include/**", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ], "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } } ], "version": 4 }
五、配置c語言的.vscode文件
在你寫代碼的地方新建文件夾和里面新建一個文件夾,然后在文件夾里面創(chuàng)建一個.vscode文件夾
然后在.vscode文件夾里面創(chuàng)建如上圖所示的四個文件,文件名如下launch.json
tasks.jsonlaunch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", // 配置名稱,將會在啟動配置的下拉菜單中顯示 "type": "cppdbg", // 配置類型,這里只能為cppdbg "request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加) "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 將要進行調(diào)試的程序的路徑 "args": [], // 程序調(diào)試時傳遞給程序的命令行參數(shù),一般設(shè)為空即可 "stopAtEntry": false, // 設(shè)為true時程序?qū)和T诔绦蛉肟谔帲话阍O(shè)置為false "cwd": "${workspaceFolder}", // 調(diào)試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄 workspaceRoot已被棄用,現(xiàn)改為workspaceFolder "environment": [], "externalConsole": true, // 調(diào)試時是否顯示控制臺窗口,一般設(shè)置為true顯示控制臺 "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/gdb.exe", // miDebugger的路徑,注意這里要與MinGw的路徑對應(yīng) "preLaunchTask": "gcc", // 調(diào)試會話開始前執(zhí)行的任務(wù),一般為編譯程序,c++為g++, c為gcc "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ] } ] }
tasks.json
{ "version": "2.0.0", "command": "gcc", "args": [ "-g", "${file}", "-o", "${fileBasenameNoExtension}.exe" ] }
感謝你能夠認真閱讀完這篇文章,希望小編分享的“vscode怎么配置c語言編譯環(huán)境”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!