使用 gcc 的文件格式

Isa*_* D. 2 c

我在一个文件中写了一些 c 代码并用 gedit 保存它。

然后我打开终端并尝试用 gcc 编译它,但它给了我一个错误,它不能识别我的 c 文件的格式。

gcc读取什么格式?

ste*_*ver 9

gcc 使用文件扩展名(后缀)来确定类型 - 您是否使用 .c 后缀命名您的文件?如果没有,请尝试重命名它 - 例如,如果我有一个名为“testc”的文件

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

然后

$ gcc -o test testc
testc: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

但是在重命名为正确的 .c 文件后

$ mv testc test.c
$ gcc -o test test.c
$ 
$ ./test
THIS is a C-file
Run Code Online (Sandbox Code Playgroud)