I have some question about compiling .cpp inside a folder, it says
first.cpp No such file or directory
but when I run it in home it compiles. Any settings I might have left out? Thanks.
Here's the Terminal output (view it bigger):
law@ubuntu:~$ ls
android-sdk Downloads Pictures test wallpapers
android-sdks eclipse Public tomcat workspace
Desktop examples.desktop sourcecodescpp Ubuntu One
Documents Music Templates Videos
law@ubuntu:~$ dir sourcecodescpp
first.cpp
law@ubuntu:~$ g++ first.cpp
g++: error: first.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
law@ubuntu:~$ ./a/out
bash: ./a/out: No such file or directory
law@ubuntu:~$ ls
android-sdk Downloads Pictures test wallpapers
android-sdks eclipse Public tomcat workspace
Desktop examples.desktop sourcecodescpp Ubuntu One
Documents Music Templates Videos
law@ubuntu:~$ dir ls
dir: cannot access ls: No such file or directory
law@ubuntu:~$ ls
android-sdk Downloads Music Templates Videos
android-sdks eclipse Pictures test wallpapers
Desktop examples.desktop Public tomcat workspace
Documents first.cpp sourcecodescpp Ubuntu One
law@ubuntu:~$ g++ first.cpp
law@ubuntu:~$ ./a.out
Hello World!law@ubuntu:~$ ^C
law@ubuntu:~$ ^C
law@ubuntu:~$
You were in your home folder (
/home/law
) when you issued theg++ first.cpp
command. Butfirst.cpp
is located in thesourcecodescpp
folder. To compilefirst.cpp
, you must either enter the folder that contains it:(Then the output file will, by default, be created inside
sourcecodescpp
.)Or qualify its name with the name of the folder that contains it:
(Then the output file will, by default, be created inside your home folder.)
You need to move (change directory, or
cd
) into thesourcecodescpp
dirctory first, to run/compile any files in there. For that please runfrom the Terminal and now you'll be in that directory.
Now you can run
to compile and
to run.
That's right, you can give full path to your cpp file to avoid such error.
I think even following should work: