1

everyone

Here's my problem; So, I'm new to Ubuntu and programming and I just wanted to start with C. I created the classic "hello.c" file

#include <stdio.h>   
main ()
{
    printf("Hello World!");
}

Then I typed within the terminal:

cd /Desktop

Because the file is located in Desktop

And then I typed

gcc hello.c -o hello

But here come the troubles, it suddenly appeared a problem that says:

gcc: error: hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

So, how can I fix that?

1
  • I seem to recall gcc used to just say "no input files" That seems less confusing.
    – j0h
    Apr 10, 2015 at 17:47

2 Answers 2

5

Desktop is not located at /Desktop rather it is located at ~/Desktop. Thus execute these commands.

  1. cd ~/Desktop (for changing directory to Desktop)
  2. gcc hello.c -o hello (for compiling C program)
  3. Then execute your application by ./hello , if it shows any error change its permissions with chmod +x hello
1
  • 4
    gcc gives it +x by default, I thought... at least in 14.04 and later.
    – Thomas Ward
    Apr 10, 2015 at 18:11
3

Then I typed within the terminal: cd /Desktop

/Desktop is not the path to your desktop. /Desktop is the path to a directory "Desktop" in / (your root directory). /home/<username>/Desktop or, shortened, ~/Desktop is the path to your desktop.

So first change your terminal's working directory to your desktop's path:

cd ~/Desktop

Then compile the file again:

gcc hello.c -o hello

You must log in to answer this question.

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