Segmentation Fault在Hello World程序上发生。

huangapple go评论73阅读模式
英文:

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++文档,但似乎无法使其正常工作。

Segmentation Fault在Hello World程序上发生。

更新:
在尝试解决问题后,我发现只有在VS-Code中执行时它才不工作!

英文:

This is my code:

#include &lt;iostream&gt;

int main() {
    std::cout &lt;&lt; &quot;Hello World!&quot;;
    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 &lt;&lt; &quot;Hello World!&quot;;

I have followed all tutorials on official docs, like VS-Code C++ docs, but can't seam to make it work.

Segmentation Fault在Hello World程序上发生。

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

huangapple
  • 本文由 发表于 2023年7月11日 03:57:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76656944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定