英文:
Segmentation Fault on Hello World Program
问题
这是我的代码:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
我正在使用VS-Code作为我的编译器,编译器版本信息如下:
g++ --version
g++.exe (Rev6, Built by MSYS2 project) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
当我进行调试时,它在std::cout << "Hello World!";
处显示"分段错误"。
我已经按照官方文档中的所有教程,如VS-Code C++文档,但似乎无法使其正常工作。
更新:
在尝试解决问题后,我发现只有在VS-Code中执行时它才不工作!
英文:
This is my code:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
I am using VS-Code with g++ as my Compiler.
g++ --version
g++.exe (Rev6, Built by MSYS2 project) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
When I debug it, it shows me "segmentation error" at std::cout << "Hello World!";
I have followed all tutorials on official docs, like VS-Code C++ docs, but can't seam to make it work.
UPDATE:
After trying to figure out the Problem I have found that it only doesn't work when executing it in VS-Code!
答案1
得分: 2
一个DLL问题。确保MSYS2是您的PATH中的第一个条目,既在系统范围内也在用户范围内(C:\msys64\mingw64\bin,将mingw64替换为您正在使用的环境)。 - HolyBlackCat
解决了我的问题。我只需要重新启动VS-Code。
英文:
A DLL issue. Make sure MSYS2 is the first entry on your PATH, both system-wide and user-specific (C:\msys64\mingw64\bin, substitute mingw64 for the environment you're using). –
HolyBlackCat
Fixed my Issue. I just had to restart VS-Code as well
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论