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?

1 Answer 1

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
1
  • 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 Aug 21, 2013 at 3:23

You must log in to answer this question.

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