无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?
我知道有其他的方式来实现这一点,但我很好奇,是否有一个标志,只为的要通过的源$ C $ C查找错误/警告。
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只
选项。它不写入磁盘上的任何东西,只是检查了code是有效的。
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, "\t.file\t\"a.c\"\n\t.text\n\t.globl\tfoo\n"..., 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, "\0a.c\0foo\0", 9) = 9
[pid 14183] write(3, "U\211\345]\303\0GCC: (Ubuntu 4.8.2-19ubunt"..., 42) = 42
[pid 14183] write(3, "\24\0\0\0\0\0\0\0\1zR\0\1|\10\1\33\f\4\4\210\1\0\0\34\0\0\0\34\0\0\0"..., 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屋!