[英]g++ does not make any file or give any output
I've just started using g++, downloading the latest version from the site, and I've made a simple HelloWorld program.我刚开始使用 g++,从该站点下载最新版本,并制作了一个简单的 HelloWorld 程序。
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
When I try to execute using the powershell window and g++, in the right directory, I use the following command:当我尝试使用 powershell window 和 g++ 执行时,在正确的目录中,我使用以下命令:
g++ HelloWorld.cpp -o HelloWorld.exe
This gives no output and makes no files.这不会给出 output 并且不会生成任何文件。 I used the -v command as per some other answer I read on the site and it gave me this.
我根据我在网站上阅读的其他答案使用了 -v 命令,它给了我这个。 I don't know how to proceed and execute my program.
我不知道如何继续和执行我的程序。
Command 命令
g++ HelloWorld.cpp -o HelloWorld.exe
does not execute propgam, it just build executable file HelloWorld.exe
. 不执行propgam,它只是构建可执行文件
HelloWorld.exe
。
So, after g++ HelloWorld.cpp -o HelloWorld.exe
check the appearance of HelloWorld.exe
file. 因此,在
g++ HelloWorld.cpp -o HelloWorld.exe
检查HelloWorld.exe
文件的外观。 If it is, just run it like: 如果是这样,只需像这样运行它:
.\HelloWorld.exe
The accepted answer from Didier helped me solve the same problem. Didier 接受的答案帮助我解决了同样的问题。 In my case
HelloWorld.exe
could use printf
without any problem, but std::cout
produced no output in the Windows console.在我的例子中,
HelloWorld.exe
可以毫无问题地使用printf
,但是std::cout
在 Windows 控制台中没有产生 output。
The HelloWorld.exe
can be inspected by dumpbin.exe /imports HelloWorld.exe
( dumpbin.exe
is distributed with Visual Studio 2019). HelloWorld.exe
可以通过dumpbin.exe /imports HelloWorld.exe
检查( dumpbin.exe
随 Visual Studio 2019 一起分发)。 In my case this showed a dependency on MinGW's libstdc++-6.dll
, which again is dependent on MinGW's libgcc_s_seh-1.dll
and libwinpthread-1.dll
.在我的例子中,这显示了对 MinGW 的
libstdc++-6.dll
的依赖,它又依赖于 MinGW 的libgcc_s_seh-1.dll
和libwinpthread-1.dll
。
Bottom line: the solution is to add the MinGW bin folder to your path, like suggested by Carucel.底线:解决方案是将 MinGW bin 文件夹添加到您的路径中,就像 Carucel 所建议的那样。 When the path is correctly configured you can use the 'where' command (from CMD) to verify the needed DLLs can be found (eg:
where libstdc++-6.dll
).正确配置路径后,您可以使用“where”命令(来自 CMD)来验证是否可以找到所需的 DLL(例如:
where libstdc++-6.dll
)。
I've had the same issue and, after running it with the traditional batch console instead of powershell, I noticed a dll
was missing. 我遇到了同样的问题,在使用传统的批处理控制台而不是Powershell运行它之后,我发现缺少一个
dll
。 The dll error won't pop up in the powershell command line (god only knows why). dll错误不会在powershell命令行中弹出(上帝只知道为什么)。
In my case it was libisl-15.dll
, but it may be different on your PC. 就我而言,它是
libisl-15.dll
,但在您的PC上可能有所不同。
Hope this helps someone in the world! 希望这可以帮助世界上的某人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.