1
votes

Compiling C program using gcc is very simple. Just such a command:

gcc code.c -o executable

However, if the code file name does not end with ".c", gcc will treat it as a linker script. How can I use gcc to compile C program whose name does not end with ".c"?

2
Rename the file with a .c - Rob

2 Answers

3
votes

Use -x switch to specify the language.

gcc -xc -o executable anything

You can even read from stdin:

echo 'int main() { printf("Hello world"); }' | gcc -xc -o executable -
3
votes

With GCC, the -x switch specifies the language to compile for:

gcc -x c code.foo -o executable