When i tried to run hello program of C on the terminal the following error comes:
$ gcc hello.c -o hello
gcc: error: hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated. 2 3 Answers
The clue is in the No such file or directory; it can't find the right file. Either...
You're not in the same directory as your
hello.cfile.cdto the right directory, or use providegccwith the path to the file:gcc /home/oli/Desktop/hello.c -o helloNote the same applies to the
-ooutput path. If you leave it ashelloit will try to write to the current working directory (/home/$USER/by default). Either change directory or provide a full path.Or you've called it
HellO.C(Ubuntu's filesystems are case sensitive).hello.cnever existed. Perhaps it was just a figment of our collective imaginations; perhaps you forgot to save it; perhaps it's called something else completely.
This is the second time you've posted about path issues. It's something you'll learn but yeah, commands don't just work globally and not all files live in the same directory. You have to specify where stuff is.
You should first check the path properly, Whether your c file does exist in this folder or not. For that, you can use ls command to list out all the files in this particular folder.
And for seeing the path for the folder, You can use pwd.
Hope this will help you. Because to compile the c file you have entered the right command only.
I had the same problem while using CMakeLists to compile some C programs. I used # in the following to comment the rest of flags:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-format -Wno-unused-label -Wno-unused-function # -Wno-int-to-void-pointer-cast -Wno-self-assign")but it turns out that I can't comment it like that so I just removed the rest (# -Wno-int-to-void-pointer-cast -Wno-self-assign) and it compiled.