提问人:RLimon 提问时间:11/12/2023 最后编辑:RLimon 更新时间:11/12/2023 访问量:115
在命令行上运行但未在 Visual Studio Code 上运行时,C++ HelloWorld 程序上出现分段错误 (Windows 10)
Segmentation fault on C++ HelloWorld program when ran on command line but not Visual Studio Code (Windows 10)
问:
我可以通过 VisualStudioCode 运行 C++ 程序,但是如果我尝试从命令行运行它,我会得到一个分段错误。问题似乎来自C:\Program Files\Git\mingw64\bin\libstdc++-6.dll
更新:从 C:\Program Files\Git\mingw64\bin\ 中删除 libstdc++-6.dll 允许程序在命令行上运行。不完全确定为什么。
我已经查看了我的 ENV 变量是否有任何问题,但一无所获。https://code.visualstudio.com/docs/cpp/config-mingw,我按照这篇文章安装了编译器。它适用于编译我想要的 c 程序。我使用了默认设置,所以我的路径变量是 C:\msys64\ucrt64\bin。我尝试像其他帖子建议的那样将变量向上移动,但没有任何变化。我将此变量作为用户和系统路径变量的一部分。我也尝试将其从 C:\msys64\ucrt64\bin 更改为 C:\msys64\mingw64\bin。
当我使用 gdb 单步执行程序时,结果是:
正在读取 helloWorld 中的符号... (gdb) 运行 启动程序:C:\Users\user\Desktop\Code\C++\helloWorld.exe [新线程 21684.0x52f8] [新线程 21684.0x4c6c] [新线程 21684.0x3b10]
线程 1 接收到信号 SIGSEGV,分段故障。 0x00007ff8c5c363a6 ??() 来自 C:\Program Files\Git\mingw64\bin\libstdc++-6.dll
我用来编译程序的命令:
g++ -g -o helloWorld helloWorld.cpp
$ ./helloWorld
分段故障
奇怪的是,当我尝试使用 VSC 运行代码时,它实际上有效。我想知道为什么它会使用 VSC 而不是命令行工作,以及如何让它在命令行上工作。
几年前,我安装了cygwin64。我不知道这是否相关或可能以某种方式干扰
这是我的helloWorld代码,仅供参考:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
return 0;
}
答: 暂无答案
评论
./helloWorld
gdb
helloWorld.exe
C:\msys64\ucrt64\bin
cp