Don Don - 1 month ago 8
C++ Question

g++ error no such file or directory

I keep getting this error when I try to compile a

.cpp
file in my unix terminal.

Here is my command:

-bash-4.2$ g++ -o test.cpp test


Output:

g++: error: test: No such file or directory
g++: fatal error: no input files
compilation terminated.


But, when I type in
ls
:

test.cpp


Do I have the wrong version of g++?

Answer

Your command line is wrong. Try this

g++ -o test test.cpp

The syntax is -o <output-file>, but you had your input file listed there, so g++ was looking for test as an input file.

Comments