g++ does not make any file or give any output
Asked Answered
U

3

6

I've just started using g++, downloading the latest version from the site, and I've made a simple HelloWorld program.

#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:

g++ HelloWorld.cpp -o HelloWorld.exe

This gives no output and makes no files. I used the -v command as per some other answer I read on the site and it gave me this. I don't know how to proceed and execute my program.

OUTPUT After DIR

Unsnarl answered 29/7, 2017 at 18:6 Comment(12)
This looks like valid code and valid compilation command. It should not output anything to console, but should produce executable (which may require libstdc++). Try running g++ using full path to g++.exeOrthography
What does "... makes no files" means? Can you provide list of files in the folder "C++" after execution of g++? (just add command and make new screenshoot)Prandial
@VTT My path is C:\MinGW\bin in environmental variables. I'm not sure what more I should add.Unsnarl
@Prandial Here's the output. !image There's no .o or .exe files made.Unsnarl
"the site, " - what site?Diarmuid
Have you tried g++ HelloWorld.cpp without specifying output? Is result the same: no a.out generated?Prandial
@Diarmuid #23842660Unsnarl
@Prandial Yes. No files are generated.Unsnarl
If there were no permission to create the file, we would see a write error message, so only to options I can come up with: 1) file created in some other location (I do not know why - just try to search HelloWorld.exe over the while drive C:); 2) something is wrong with the tools and/or environment (Try to reinstall mingw, and others)Prandial
you should explain how and where you got the compiler. There are many different versions of g++ for windows.Diarmuid
@Unsnarl did you ever figure out what was going on? I am having the same issue, and none of these answers solved the problem.Structuralism
@Structuralism I gave up and switched to Ubuntu.Unsnarl
S
11

I've had the same issue and, after running it with the traditional batch console instead of powershell, I noticed a dll was missing. The dll error won't pop up in the powershell command line (god only knows why).

In my case it was libisl-15.dll, but it may be different on your PC.

Hope this helps someone in the world!

Serge answered 12/3, 2018 at 14:19 Comment(3)
Thank you very much! I don't know why the powershell does not show the error, but I know adding MinGw to the path solves the problem.Arboriculture
In my case missing mingw-w64-x86_64-isl 0.25-1 prevented gcc version 12.2.0 from creating compiler or linker output files.Tincher
Same thing, no generated files and no error messages. I switched to another build (winlibs with gcc 11.3.0 instead of 12.2.0) and the problem is gone.Rellia
P
4

The accepted answer from Didier helped me solve the same problem. In my case HelloWorld.exe could use printf without any problem, but std::cout produced no output in the Windows console.

The HelloWorld.exe can be inspected by dumpbin.exe /imports HelloWorld.exe (dumpbin.exe is distributed with 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.

Bottom line: the solution is to add the MinGW bin folder to your path, like suggested by Carucel. When the path is correctly configured you can use the 'where' command (from CMD) to verify the needed DLLs can be found (e.g.: where libstdc++-6.dll).

Perversion answered 26/9, 2021 at 20:10 Comment(1)
In my case, running "where libstdc++-6.dll" lead me to discover that Inkscape had its own libstdc++-6.dll that was above the MinGW libstdc++-6.dll in my system environment variables path. I moved the MinGW path above the Inkscape path in my system environment variables path and it fixed it.Jakoba
P
3

Command

 g++ HelloWorld.cpp -o HelloWorld.exe

does not execute propgam, it just build executable file HelloWorld.exe.

So, after g++ HelloWorld.cpp -o HelloWorld.exe check the appearance of HelloWorld.exe file. If it is, just run it like:

 .\HelloWorld.exe
Prandial answered 29/7, 2017 at 18:38 Comment(3)
In Powershell, you need to run it with relative path: .\HelloWorld.exe or .\HelloWorldBunton
good recommendation! By default, starting from the current folder could not work - UpdatedPrandial
There's no file made. That's the issue I have. I've added the screenshot of the output after dir to the OP.Unsnarl

© 2022 - 2024 — McMap. All rights reserved.