GCC compile debug: print include files and compile stage info.

本文介绍了使用GCC编译器时的-H和-v选项的具体作用。通过-H选项可以查看到所有被包含的头文件路径,而-v选项则展示了编译过程中所使用的命令及版本信息等。这些信息对于理解编译过程和调试编译错误非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sample code:

#include <stdio.h>
#include <stdlib.h>

extern void foo() __attribute__((weak));
int main() {
  if (foo) foo();
  printf("this is a test\n");
}

Compile command:

gcc -H -v sample.c 

Compile options:

-H tells you that the right include files used.
Official document:

Print the name of each header file used, in addition to other normal
activities. Each name is indented to show how deep in the ‘#include’
stack it is. Precompiled header files are also printed, even if they
are found to be invalid; an invalid precompiled header file is printed
with ‘…x’ and a valid one with ‘…!’ .

-v (or even maybe -Wl,-v) tells you that the right libraries used.
Official document:

Print (on standard error output) the commands executed to run the
stages of compilation. Also print the version number of the compiler
driver program and of the preprocessor and the compiler proper.

Sample output:

…………………….
/usr/include/x86_64-linux-gnu/bits/waitflags.h
/usr/include/x86_64-linux-gnu/bits/waitstatus.h
/usr/include/x86_64-linux-gnu/gnu/stubs-64.h
/usr/include/x86_64-linux-gnu/gnu/stubs.h COLLECT_GCC_OPTIONS=’-o’
‘hello’ ‘-H’ ‘-v’ ‘-mtune=generic’ ‘-march=x86-64’ as -v –64 -o
/tmp/ccwD1DYA.o /tmp/cc8CU0IV.s GNU assembler version 2.24
(x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/lib/:./:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
…………..

Ref:

  1. https://gcc.gnu.org/onlinedocs/
  2. http://stackoverflow.com/questions/28563263/c-compiling-errors-on-debian
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值