首先根据网上的教程下载了mingw64,并新建了.vscode环境。
文末贴上了这三个json文件的内容。
接下来讲讲我在配置的过程中遇到的一些问题。
第一次配置是在去年准备打蓝桥杯的时候,由于我本身学的是前端,对vscode感到十分亲切,但是后面配置不大理想,记得当时是只能在powershell上丑陋地显示一下结果,并且运行得等个一两秒,极度不舒适,后面开始转战devc++。
后面图形引擎课程作业需要配置opengl环境。不得不再次配c++环境~遇到了如下几个简单的小问题:
遇到的3个问题
1. “终端将被任务重用,按任意键关闭”
原解答 原因是本地窗口是共享的,需要结束一个才能执行另一个,有两种解决方法:1.为每个进程创建一个新端口;2.把端口聚焦到当前进程
"presentation": {
"focus": true
"panel": "new"
}
后面测试的halloworld成功执行,是熟悉的黑窗口,开心~
2. “unable to start debugging…is mising or valid”
这个问题我也找了网上一些博客,并且关注到了C文件要在.vscode的同级目录下或者更低级目录的条件,但后面我的解决办法是不使用英文命名,改成全英文就解决啦
3. 黑窗口一闪而过的问题
查了博客说是要在return语句前加上 getchar(); 加了这个语句后确实解决了问题,但是后面,其他文件不加这条语句也依然可以运行。
3个json文件内容
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/vscode/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "g++.exe build active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/vscode/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "g++.exe build active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/vscode/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
注意修改对应的mingw64
|