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

被折叠的 条评论
为什么被折叠?



