VSCode编译C/C++
Posted xhBruce
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VSCode编译C/C++相关的知识,希望对你有一定的参考价值。
VSCode编译C/C++
下载安装
编辑工具 Visual Studio Code
编译环境 通过 SourceForge 网站安装 Mingw-w64
Mingw-w64安装下载超慢
下载地址:https://sourceforge.net/projects/mingw-w64/files/
下载的文件找到最新版 "x86_64-posix-seh"下载压缩包
已经抓安装了C++的IDE(Dev C++等),找到对应安装的MinGW文件
配置path
C:\\Program Files\\mingw64\\bin
新建项目运行
- 新建tasks.JSON:告诉 VS 代码如何构建(编译)程序
Terminal > Configure Default Build Task > g++.exe build active file
需要打开cpp文件
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "C:\\\\Program Files\\\\mingw64\\\\bin\\\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\\\Program Files\\\\mingw64\\\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: \\"C:\\\\Program Files\\\\mingw64\\\\bin\\\\g++.exe\\""
}
]
}
- 新建launch.json:在按 F5调试程序时启动 GDB 调试器
"miDebuggerPath"要与MinGw的路径对应,“externalConsole”: true 弹出终端
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\\\Program Files\\\\mingw-w64\\\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\\\mingw64\\\\bin\\\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
}
]
}
include导入报错
无法打开 源 文件 “stddef.h” (dependency of “iostream”)
win10上新建工程运行报错无法打开包括文件: “stddef.h”
并配置"windowsSdkVersion": “10.0.14393.0”
终端一闪而过
“externalConsole”: true 弹出终端,需要等待输出或暂停
以上是关于VSCode编译C/C++的主要内容,如果未能解决你的问题,请参考以下文章
将vscode打造成无敌的IDE初步探索vscode,解放生产力