A special file, preprocessed file, is usually useful for our development. Supposed that when we are building a large project containing some header files with same name in different directories, an error occurs when some file is compiling, indicating that some symbol is not defined. After long time checking source code, we could not find out the root cause since the corresponding header file has been included. In this case, the preprocessed file could help us locate the root cause.
First of all, let's explain how to generate the preprocessed file. There are two methods to generate the preprocessed files:
1) Use option -E
gcc -c hello.c -E -o hello.i
2) Use option -save-temps
gcc -c hello.c -o hello.o -save-temps
These two methods will all generate the preprocessed hello.i, which is generated by the preprocessor of gnu toolchains.
Then you can open the file, and find whehter the file contains the missed symbol. Obviously, maybe the wrong header file with same name in other folder is included in your source code.
Above example is just a simple usage of the preprocessed file. Since this file contains all variables and functions defined in the included files, it will provide all what you want to see in the target file.
阅读(753) | 评论(0) | 转发(0) |