3

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
  • 1
    I had the same problem after having saved file in jEdit text editor (I wrote the filename in it). Removed file. Created via nano. Profit. Maybe the problem was with encoding, but to be honest, I don't know. Just try this. If it'll work then update your Question or answer on this comment.
    – yulian
    May 20, 2015 at 21:03
  • 1
    I don't think this is unclear, and I've voted to reopen it. The problem is that hello.c isn't in the current directory, which Oli's answer explains well and in a way that is still (and will continue to be) useful. This might turn out to be a duplicate of something and merit reclosure as a duplicate, but I don't think any other close reasons apply--or ever applied--to it. Nov 6, 2019 at 0:01

3 Answers 3

12

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.c file. cd to the right directory, or use provide gcc with the path to the file:

    gcc /home/oli/Desktop/hello.c -o hello
    

    Note the same applies to the -o output path. If you leave it as hello it 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.c never 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.

0

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.

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .