Unable to compile and link program

Right, so I [attempted] to create a quick, easy program to test using GCC and I'm having a bit of an issue.

  #include <iostream>

int main ()
    std::cout << "Solidum petit in profundis!\n";
    return 0;

The file is saved as Motto.cpp. In the command prompt, I entered the following command to have the file compiled and linked:

g++ Motto.cpp -o Motto.exe

However, the prompt displays an error message:

C:\\MinGW\bin>g++ Motto.cpp -o Motto.exe
g++: Motto.cpp: No such file or directory
g++: No input files

Any clue what I'm doing wrong?
You need to cd to the directory where you saved Motto.cpp - generally this is a simple as typing cd, followed by a space, and then drag the path from the explorer window into the console window to automagically paste in the path.
Motto.cpp is saved in my Documents folder. I initially created a path by going to My Computer > Properties > Advanced System Settings > Environment Variables > Path > Edit, and input ;C:MinGW\bin at the end of the path value. I'm not sure what to do, total newbie here.
That's what I figured, except I don't know where the console window is (top left of video). :x
How did you run that commandline without a console window?

Also, the top left of the video is for a different console - you're only interested in the bottom left console.
Last edited on
Oh, yeah I thought the top left was what you were talking about. I used the console for the commands. I dragged the folder where Motto.cpp is saved in into the console window. I entered g++ Motto.cpp -o Motto.exe in again and it says that "g++" is not a recognized as an internal or external command, operable program or batch file.
thesinisterminister wrote:
I initially created a path by going to My Computer > Properties > Advanced System Settings > Environment Variables > Path > Edit, and input ;C:MinGW\bin at the end of the path value.
You forgot the slash after the colon, which is why this is being ignored.

You have this:
You need this instead:
Last edited on
That was an error in my post. I had ;C:\MinGW/bin, with the wrong slash being used just before bin. I corrected it to ;C:\MinGW\bin, cd to C:\MinGW\bin, dragged the folder of the file in, input g++ Motto.cpp -o Motto.exe and it worked. It was a matter of me not paying attention when creating the path in the Environment Variables dialog.
Last edited on
Actually, void my last reply. Another error came up:

What does g++ --version say? You may want to try reinstalling your compiler. If you have a 64-bit machine, I recommend nuwen MinGW (google it).
Last edited on
Where did you find such an outdated version of gcc? The latest version is 4.8.1, you have 3.4.5! You definitely need to upgrade.

Also, in the future, use imgur ;)
Could that be the problem? Haha, I noticed the installer looked incredibly different than what was pictured in my textbook... perhaps I installed the wrong tools because of it. I'll give it a try tomorrow, it's late.
Last edited on
I reinstalled GCC, but the up-to-date 4.8.1 version. Downloaded the MinGW base tools and g++ compiler from the installer. Checked the punctuation of the program line-by-line, and everything is correct. The file was saved as Motto.cpp again. I went ahead and entered cd and dragged the file's location in, then hit enter. Entered the command g++ Motto.cpp -o Motto.exe and an error message comes up saying:

g++: Motto.cpp No such file or directory
g++: no input files

If it helps, the Variable Value is C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\12.0\DLLShared\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem\;C:\MinGW\bin

At the very end of the value the textbook instructed me to add ;C:\MinGW\bin in order to run G++ from any folder. I tested it by using the g++ --version command and it works normally. However, I cannot get Motto.cpp to compile.
Last edited on
What does it say to the left of the > in the command prompt? Does this folder contain your file?
Topic archived. No new replies allowed.