您好,登錄后才能下訂單哦!
這篇文章主要介紹了vscode怎么配置c語言編譯環(huán)境,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
一、下載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相關的插件
c++插件
重啟vscode軟件。
四、配置c++的.vscode文件
在你寫代碼的地方新建文件夾并在里面新建一個文件夾,然后在文件夾里面創(chuàng)建一個.vscode文件夾
然后在.vscode文件夾里面創(chuàng)建如上圖所示的四個文件,文件名如下:
c_cpp_properties.json
launch.json
tasks.json
請根據安裝的位置來修改文件路徑(如果跟我一樣可以不要修改)
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", // 配置名稱,將會在啟動配置的下拉菜單中顯示 "type": "cppdbg", // 配置類型,這里只能為cppdbg "request": "launch", // 請求配置類型,可以為launch(啟動)或attach(附加) "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", // 將要進行調試的程序的路徑 "args": [], // 程序調試時傳遞給程序的命令行參數,一般設為空即可 "stopAtEntry": false, // 設為true時程序將暫停在程序入口處,一般設置為false "cwd": "${workspaceFolder}", // 調試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄 workspaceRoot已被棄用,現改為workspaceFolder "environment": [], "externalConsole": true, // 調試時是否顯示控制臺窗口,一般設置為true顯示控制臺 "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/gdb.exe", // miDebugger的路徑,注意這里要與MinGw的路徑對應 "preLaunchTask": "g++", // 調試會話開始前執(zhí)行的任務,一般為編譯程序,c++為g++, c為gcc "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ] } ] }
tasks.json
如果遇到找不到文件 比如這樣:
把 "${workspaceFolder}"替換為 "\\"或 "//"
{ "version": "2.0.0", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileBasenameNoExtension}.exe" ], // 編譯命令參數 "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"設置問題 路徑獲取獲取方法為: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", // 將要進行調試的程序的路徑 "args": [], // 程序調試時傳遞給程序的命令行參數,一般設為空即可 "stopAtEntry": false, // 設為true時程序將暫停在程序入口處,一般設置為false "cwd": "${workspaceFolder}", // 調試程序時的工作目錄,一般為${workspaceRoot}即代碼所在目錄 workspaceRoot已被棄用,現改為workspaceFolder "environment": [], "externalConsole": true, // 調試時是否顯示控制臺窗口,一般設置為true顯示控制臺 "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/gdb.exe", // miDebugger的路徑,注意這里要與MinGw的路徑對應 "preLaunchTask": "gcc", // 調試會話開始前執(zhí)行的任務,一般為編譯程序,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)境”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業(yè)資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。