因为VSCode比较轻量级,同时又具有很多插件,界面也不错,就想转用VSCode环境。谁知道配置的过程还真是一波三折,遇到了蛮多问题,从头配置了n遍。还好,折腾到最后大多数问题还是解决了。
大家要先从下方的控制台看一下,到底是哪里出错(超级重要,超级重要,超级重要)了,如果看不懂简单的MinGW编译指令,建议补一补相关知识(很快),否则就不要用VSCode了,用VS更好点,不然会更浪费时间。
比如像这种错误,(很多时候的terminated with exit code: 1)
大家都知道的,首先需要做的事是下载安装VSCode、MinGW编译包以及修改电脑的环境变量
1.运行的时候报错,permission denied
原因:即运行*.exe可执行文件的时候报错,很大可能是这个可执行文件已经存在进程了。
解决:用任务管理器,把*.exe进程关闭,然后重新编译运行
2.编译的时候报错,skipping incompatible
原因:我当时这个问题的原因是编译器32位和64位的问题,我用64的编译环境会出现这个问题
解决:重新配置32位的环境 (下方附我是用的32位编译包)
3.GDB Debug的时候,无法查看STL内容,看到的是地址信息
原因:编译器版本问题
解决:更换编译器
4.编译的时候,multiple definition of ....
原因:配置文件问题
解决:检查json文件的参数,tasks.json和launch.json
附:
一.重新配置环境,最佳参考(官方,使用的是64位编译环境)
https://code.visualstudio.com/docs/cpp/config-mingw
二.我根据官方重新配置的(32位)环境,可以正常运行及在窗口查看STL容器内容
1.使用的编译包:
链接:https://pan.baidu.com/s/18TtC6GmqYXaoHigt7R0wRQ
提取码:37br
2.使用的VSCode版本
August 2020 (version 1.49)
3.环境变量修改完成
4.我的json文件(使用的话记得修改编译路径)
(只配置了编译当前文件,若需编译多文件,请自行修改tasks.json)
可以在主目录下创建.vscode文件夹,里面配置三个文件(忽略settings.json)
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "Q:\\MinGW\\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json
{
"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": "Q:\\MinGW\\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "gcc",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"compilerPath": "Q:/MinGW/i686-8.1.0-release-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe",
"cStandard": "c11",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}
最后放一张编译时候的图
使用中的一些问题,参见:https://blog.csdn.net/s_y_w123/article/details/88877524