@
目录前言
说明下如何在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,
}
标签:false,VSCode,C++,editor,&&,fileNameWithoutExt,true,dir,搭建
From: https://www.cnblogs.com/Wei-Ting/p/16807341.html