1

I am having issues with compiling my .cpp file. There is nothing wrong with the code, and I suck at C++ and g++, so sorry if I suck at this. Anyways, I am getting the error message:

'Main.cpp -o Main
error: Main.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.`

Any idea as to why this might be happening?

4
  • 1
    Maybe you're in the wrong directory. Commented Mar 4, 2014 at 18:13
  • Show the compilation command Also, are you sure Main.cpp is present in current working folder ? Commented Mar 4, 2014 at 18:13
  • I am sure it is in the current working folder. Commented Mar 4, 2014 at 18:18
  • 2
    If this is Linux, remember that file names are case sensitive, i.e., Main.cpp is not the same as main.cpp or even mAiN.cPp. You can have all three (and even more) for kicks. Commented Mar 4, 2014 at 19:17

2 Answers 2

4

Say you have file main.cpp inside of directory foo. To compile it with GCC, you navigate to foo and issue this command:

g++ main.cpp

This has to work. There's not much more to it.

Sign up to request clarification or add additional context in comments.

7 Comments

@πάνταῥεῖ Issuing this command won't generate any object file at all.
@faranwath, it sure does. For reasons lost in the mists of Unix prehistory, if you ask a compiler to write an executable, but don't give it a name, it is christened a.out.
@πάνταῥεῖ, the -o outputfile flag can be given almost anywhere in the commandline (at least for GCC, it's been quite a while since I've had to wrangle with propietary compilers...).
@vonbrand Oh well, if you want to be that exact, yes, the a.out is an object format. I only meant if won't give you an object file like -c does.
@vonbrand Yes! I've tried with my GCC 4.8.2 and the order didn't matter.
|
3

The command

g++ -o Main Main.cpp

should create an executable named Main from your source files directly. The error message says that you either didn't specify any input files, or they can't be found in the current working directory (though I'd expect a message like error: Cannot open 'Main.cpp' then). Also be sure about the source filename spelling, when running the command from an OS supporting case sensitive filenames.

Saying

g++ Main.cpp

will create an executable file named a.out (which is the default name).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.