Error compiling C in gcc: No such file or directory

Asked

Viewed 8,213 times

1

I’m trying to compile a file. c but I’m not getting it.
I type the following command:

gcc main.c -o HELLO

and the following error appears:

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

I did the following in the notebook itself:

include <stdio.h>

   int main()
    {
        printf("Hello World\n");
      return(0);
     }

What to do??

  • 1

    You are in the folder that contains the file main.c?

  • The ta file on the Desktop, has difference?

  • Of course there is! Look at my answer

  • You use Linux or Windows, in Linux I usually give the commands cd to reach the file location and execute the command.

  • In the Windows is also cd

1 answer

5


Error says you could not find the file main. c.

To compile the file, don’t just log in to cmd and type

gcc file. c -o executable

Either you need to be in the folder the file is in, or you need to indicate the full path of the file:

Example (with the file main. c in the Desktop):

Full path:

gcc C: Users Seuusuario Desktop main. c -o HELLO

Changing directory:

cd C: Users Seuusuario Desktop

gcc main. c -o HELLO

Browser other questions tagged

You are not signed in. Login or sign up in order to post.