在 GCC 中编译而不生成输出文件 [英] Compile without generating output file in GCC
问题描述
$ gcc -c somefile.c
编译不链接,生成对应的somefile.o
.
$ gcc -c somefile.c
compiles without linking and generates the corresponding somefile.o
.
是否可以在 gcc
中编译文件而不生成任何输出文件?
Is it possible to compile files in gcc
without generating any output file?
我知道还有其他方法可以实现这一点,但我很好奇是否有一个标志仅用于遍历源代码以查找错误/警告.
I know there are other ways to achieve this but I'm curious on whether there is a flag just for going through the source code looking for errors/warnings.
推荐答案
您可能喜欢 -fsyntax-only
选项.它不会在磁盘上写入任何内容,只是检查代码是否有效.
You may like the -fsyntax-only
option. It does not write anything on disk, just checks that the code is valid.
您可以使用以下命令检查它是否没有在磁盘上写入任何内容:
You can check that it does not write anything on disk with this command:
$ strace -e write -f gcc -fsyntax-only test.c
Process 14033 attached
[pid 14033] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=14033, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++
与使用 -c -o/dev/null
的其他命令进行比较:
Compare with this other command that uses -c -o /dev/null
instead:
rodrigo@P41CCTX5:/tmp$ strace -e write -f gcc -c -o /dev/null test.c
Process 14182 attached
[pid 14182] write(3, " .file "a.c"
.text
.globl foo
"..., 353) = 353
[pid 14182] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=14182, si_status=0, si_utime=0, si_stime=1} ---
Process 14183 attached
[pid 14183] write(3, " a.c foo ", 9) = 9
[pid 14183] write(3, "U211345]303 GCC: (Ubuntu 4.8.2-19ubunt"..., 42) = 42
[pid 14183] write(3, "24 1zR 1|10133f442101 34 34 "..., 56) = 56
....
[pid 14183] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=14183, si_status=0, si_utime=0, si_stime=0} ---
+++ exited with 0 +++
这篇关于在 GCC 中编译而不生成输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!