我最近从msys2安装了mingw,并测试了下面的程序:
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World" ;
return 0 ;
}
但是我在VS代码中得到了一个分段错误。
相同的代码在CodeBlocks(edit)和mingw终端中运行良好。
似乎每当有cout或cin语句时,我都会得到错误。
我确实做了pacman -Syuu
来更新msys2包,但没有用。
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": " ${workspaceFolder}/${fileBasenameNoExtension}.exe",
// "sourceFileMap": {
// "/mnt/c": "C:/msys64/mingw64"
// },
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe ",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
]
}
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
谢谢
1条答案
按热度按时间w7t8yxp51#
经过大量徒劳的尝试来修复错误,我设法解决了这个问题,通过将
mingw\bin
的路径移动到用户和系统变量路径列表中环境变量的顶部。问题的根源是我有多个不同应用程序的
libstdc++-6.dll
文件,其路径高于msys2libstdc++-6.dll
的路径,这导致调用了错误的库版本。