Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 6329  / 3 Years ago, mon, november 8, 2021, 9:33:14

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):
enter image description here



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:~$

More From » 12.04

 Answers
2

You were in your home folder (/home/law) when you issued the g++ first.cpp command. But first.cpp is located in the sourcecodescpp folder. To compile first.cpp, you must either enter the folder that contains it:



cd sourcecodescpp


(Then the output file will, by default, be created inside sourcecodescpp.)



Or qualify its name with the name of the folder that contains it:



g++ sourcecodescpp/first.cpp


(Then the output file will, by default, be created inside your home folder.)


[#38107] Wednesday, November 10, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gliroopy

Total Points: 290
Total Questions: 115
Total Answers: 114

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;