我意识到这可能会被 stackoverflow 拒绝,但是:
我使用编译器生成 .s 文件以供 gcc 汇编。我也混合了 C 文件,因此最终的 gcc 命令行包含 .s 和 .c 文件的混合。因为 .s 文件对我来说只是一个中间文件,所以我想在 make clean 中删除它们的all。于是问题就来了。有 .s 文件、汇编文件,其中包含手写代码和生成的其他 .s 文件。如果(比如说).asm 是 .s 文件的正确替代品,这将是一个理想的解决方案,这样我就可以将我想要保留为 .asm 文件的程序集文件,而 .s 文件是可以删除的垃圾文件。 .s 文件还有其他替代方案吗? (扩展名)?
搜索发现了 .S 和 .sx 扩展名,但每个扩展名都有特殊含义。我(理想情况下)想要 .s 文件的正确别名。
我实际上尝试了 .asm 作为扩展名,我得到:
$ gcc test.asm -o test
/usr/bin/ld:test.asm: file format not recognized; treating as linker script
/usr/bin/ld:test.asm:1: syntax error
collect2: error: ld returned 1 exit status
提前致谢。
是的,您可以将程序集文件保留为例如
file.asm
和
只需告诉 gcc
将它们视为汇编源即可:
gcc -x assembler -o file.o file.asm
或者告诉你的构建系统告诉
gcc
这样做。
-x language
Specify explicitly the language for the following input files
(rather than letting the compiler choose a default based on the
file name suffix). This option applies to all following input files
until the next -x option. Possible values for language are:
c c-header cpp-output
c++ c++-header c++-system-header c++-user-header c++-cpp-output
objective-c objective-c-header objective-c-cpp-output
objective-c++ objective-c++-header objective-c++-cpp-output
assembler assembler-with-cpp
ada
d
f77 f77-cpp-input f95 f95-cpp-input
go