2

I wrote some c code in a file and saved it with gedit.

I then opened the terminal and tried compiling it with gcc but it gives me an error that it does not recognize the format of my c file.

What format does gcc read?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Isaac D.
  • 41
  • 1
  • 1
  • 3

1 Answers1

9

gcc uses the file extension (suffix) to determine the type - did you name your file with a .c suffix? If not, try renaming it - for example if I have a file called 'testc'

$ cat testc
#include<stdio.h>
int main()
{
printf("THIS is a C-file\n");
return 0;
}

Then

$ gcc -o test testc
testc: file not recognized: File format not recognized
collect2: ld returned 1 exit status

But after renaming to a proper .c file

$ mv testc test.c
$ gcc -o test test.c
$ 
$ ./test
THIS is a C-file
steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • Generally, as long as (a) your source code contains all the pieces necessary for a complete program, including an entry point ('main' function); and (b) and you don't explicitly tell gcc to stop before linking (with the '-c' option); and (c) you specify any additional non-standard libraries that your code requires on the command line, then gcc will produce a binary file that is executable on the platform on which it is compiled – steeldriver Aug 21 '13 at 03:23