c++环境准备
一、VScode c++编译环境配置
https://blog.youkuaiyun.com/Zhouzi_heng/article/details/115014059
1.mingw
下载并解压缩mingw,配置环境变量
2.c_cpp_properties.json
1)includePath路径
打开cmd,输入gcc -v -E -x c++ -
2)文件
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
// 以下7行需要修改
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
// 以下7行需要修改
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"G:/Software/c++setting/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
]
}
}
],
"version": 4
}
3.launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${workspaceFolder}/exe/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录
"environment": [],
"externalConsole": false, // true则弹出终端,false会在下方terminal直接输出
"MIMode": "gdb",
// 这里的路径需要修改。改成自己的路径
"miDebuggerPath": "G:/Software/c++setting/mingw64/bin/gdb.exe",
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
4.tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}/exe/${fileBasenameNoExtension}.exe"
], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"\\"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
二、报错
include以后,报错
VScode:ERROR: Unable to start debugging. Unexpected GDB output from command “-exec-run
原因
环境变量中,有多个libstdc++ -6.dll
方案
将mingw/bin对应的环境变量向上调整
https://blog.youkuaiyun.com/flyaaa123/article/details/125069936