@(文章目錄) 前言 說明下如何在VSCode下麵搭建C/C++環境以及運行 下載 點擊該鏈接,進行ming64安裝包下載:ming64安裝包 VSCode安裝請自行百度,這裡不在贅述。 安裝 將下載完成後的安裝包,解壓放到C盤下麵即可,如下圖所示: 添加環境變數 在我的電腦上點擊右鍵-->屬性:進 ...
@
目錄前言
說明下如何在VSCode下麵搭建C/C++環境以及運行
下載
點擊該鏈接,進行ming64安裝包下載:ming64安裝包
VSCode安裝請自行百度,這裡不在贅述。
安裝
- 將下載完成後的安裝包,解壓放到C盤下麵即可,如下圖所示:
- 添加環境變數
在我的電腦上點擊右鍵-->屬性:進入環境變數配置C:\mingw64\bin; (要與mingw64安裝位置相對應)
設置.vscode
在對應的工程目錄下麵新建.vscode文件,並且對應創建如下三個文件
c_cpp_properties.json
將下麵內容直接複製到該文件下麵即可
{
"configurations": [
{
//win32 操作系統名字
"name": "Win32",
// 提供.h文件的搜索目錄
"includePath": [
"C:/mingw64/include",
"C:/mingw64/x86_64-w64-mingw32/include",
//根據的安裝路徑更改
"${workspaceRoot}/**"
],
//編譯時加入的巨集定義
"defines": [
"_DEBUG",
"UNICODE"
],
"browse": {
//閱讀代碼的時候 F12搜索函數的目錄
"path": [
"C:/mingw64/include",
"C:/mingw64/x86_64-w64-mingw32/include",
//根據的安裝路徑更改
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"compilerPath": "C:\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14"
}
],
"version": 4
}
launch.json
將下麵內容直接複製到該文件下麵即可
{
// 懸停以查看現有屬性的描述。
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"miDebuggerPath": "C:/mingw64/bin/gdb.exe",
"MIMode": "gdb",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"internalConsoleOptions": "openOnFirstSessionStart",
"externalConsole": false,
"preLaunchTask": "gcc"
}
]
}
settings.json
將下麵內容直接複製到該文件下麵即可
{
"files.associations": {
"stdarg.h": "c",
"utils.h": "c",
"string.h": "c",
"typedef.h": "c",
"stdlib.h": "c",
"stdio.h": "c",
"gd32f4xx_usart.h": "c",
"gd32f4xx.h": "c",
"limits": "c",
"cmath": "cpp",
"*.tcc": "cpp",
"cstdlib": "cpp"
},
// 這裡可以設置代碼界面風格
"C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, ColumnLimit: 150, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Linux, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false}",
"code-runner.executorMap": {
"c": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
}
下載Code Runner 插件
打開VSCode, 進入應用商店,輸入Code Runner 進行插件下載安裝即可
運行代碼
接下來在對應的工程下麵 創建一個main文件,輸入代碼後,在main.c文件里點擊右鍵選擇RunCode 運行代碼即可
VSCode我個人的配置項設置
用戶區的
{
"files.autoGuessEncoding": true,
"files.trimTrailingWhitespace": false,
"files.autoSave": "afterDelay",
"files.encoding": "gb2312",
"scm.alwaysShowActions": true,
"debug.inlineValues": "on",
"workbench.colorTheme": "Monokai",
"extensions.closeExtensionDetailsOnViewChange": true,
"extensions.ignoreRecommendations": true,
"update.mode": "manual",
"update.showReleaseNotes": false,
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"security.workspace.trust.untrustedFiles": "open",
"cnblogsClientForVSCode.workspace": "e:\\other\\wei-ting",
"git.path": "C:\\soft\\Git\\Git\\cmd\\git.exe",
"git.ignoreMissingGitWarning": true,
"git.enableSmartCommit": true,
"git.ignoreLimitWarning": true,
"git.ignoreLegacyWarning": true,
"git.confirmSync": false,
"git.autoStash": true,
"git.alwaysShowStagedChangesResourceGroup": true,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "all",
"editor.tabSize": 4,
"editor.fontSize": 16,
"editor.detectIndentation": false,
"editor.autoClosingBrackets": "beforeWhitespace",
"editor.dragAndDrop": false,
"editor.wordWrapColumn": 180,
"editor.largeFileOptimizations": false,
"editor.formatOnSave": false,
"diffEditor.ignoreTrimWhitespace": false,
"typescript.format.enable": false,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
"C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Linux, ColumnLimit: 150, AlignConsecutiveMacros: true,}",
"C_Cpp.clang_format_sortIncludes": false,
"C_Cpp.dimInactiveRegions": true,
"code-runner.runInTerminal": true,
"code-runner.fileDirectoryAsCwd": true,
"code-runner.ignoreSelection": true,
"code-runner.showRunIconInEditorTitleMenu": true,
"code-runner.showRunCommandInEditorContextMenu": true,
"code-runner.respectShebang": true,
"code-runner.executorMap": {
"c": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"python": "python"
},
"code-runner.executorMapByFileExtension": {
".vb": "cd $dir && vbc /nologo $fileName && $dir$fileNameWithoutExt",
".vbs": "cscript //Nologo",
".scala": "scala",
".jl": "julia",
".cr": "crystal",
".ml": "ocaml",
".exs": "elixir",
".hx": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
".rkt": "racket",
".ahk": "autohotkey",
".au3": "autoit3",
".kt": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar",
".kts": "kotlinc -script",
".dart": "dart",
".pas": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
".pp": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
".d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
".hs": "runhaskell",
".nim": "nim compile --verbosity:0 --hints:off --run",
".csproj": "dotnet run --project",
".fsproj": "dotnet run --project"
},
"code-runner.languageIdToFileExtensionMap": {
"bat": ".bat",
"powershell": ".ps1",
"typescript": ".ts"
},
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"[cpp]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"workbench.editorAssociations": {
"*.exe": "default"
},
"editor.suggestSelection": "first",
"workbench.startupEditor": "none",
"markdown-preview-enhanced.previewTheme": "vue.css",
"explorer.excludeGitIgnore": true,
}