简体   繁体   中英

How can I use gcc to compile C program whose name does not end with “.c”?

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"?

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

gcc -x c code.foo -o executable`

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 -

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM