Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
11-02-2008, 11:53 PM
#1
Member
Registered: Dec 2004
Posts: 92
Rep:
who include "it"
how to trace the include path of target .h file?
for example:
file A.c:
Code:
#include "a.h";//may include d.h
#include "b.h";//may include d.h
#include "c.h";//may include d.h
...
I know d.h is included in A.c, but it's not included explicitly.
my question is: where is it from?
any tools to finish such query in more complex case?
thanks in advance!
11-03-2008, 12:44 AM
#2
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078
Rep:
Doxygen does a good job because it documents header dependencies if you enable it. It's used to generate header references, if you haven't used it before. It's a bit much if you aren't creating something with a lot of headers that needs documentation to distribute with it.
ta0kira
11-03-2008, 12:54 AM
#3
Senior Member
Registered: May 2005
Posts: 4,481
Quote:
Originally Posted by
jackandking
how to trace the include path of target .h file?
for example:
file A.c:
Code:
#include "a.h";//may include d.h
#include "b.h";//may include d.h
#include "c.h";//may include d.h
...
I know d.h is included in A.c, but it's not included explicitly.
my question is: where is it from?
any tools to finish such query in more complex case?
thanks in advance!
Just run 'cpp' (C PreProcessor) on file(s), for example this file
Code:
cat -n curlies_return_value.c
1 #include <stdio.h>
2
3 int main()
4 {
5 int retval = ({int i = 1; int j = 2; i + j;});
6 printf("retval=%d\n", retval);
7 return 0;
8 }
produces this output:
Code:
sergei@amdam2:~/junk> cpp curlies_return_value.c | grep '#'
# 1 "curlies_return_value.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "curlies_return_value.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 28 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 322 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 324 "/usr/include/sys/cdefs.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 325 "/usr/include/sys/cdefs.h" 2 3 4
# 323 "/usr/include/features.h" 2 3 4
# 345 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 5 "/usr/include/gnu/stubs.h" 2 3 4
# 1 "/usr/include/gnu/stubs-32.h" 1 3 4
# 8 "/usr/include/gnu/stubs.h" 2 3 4
# 346 "/usr/include/features.h" 2 3 4
# 29 "/usr/include/stdio.h" 2 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 1 3 4
# 214 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 3 4
# 35 "/usr/include/stdio.h" 2 3 4
# 1 "/usr/include/bits/types.h" 1 3 4
# 28 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 29 "/usr/include/bits/types.h" 2 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 1 3 4
# 32 "/usr/include/bits/types.h" 2 3 4
# 134 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/typesizes.h" 1 3 4
# 135 "/usr/include/bits/types.h" 2 3 4
# 37 "/usr/include/stdio.h" 2 3 4
# 45 "/usr/include/stdio.h" 3 4
# 65 "/usr/include/stdio.h" 3 4
# 75 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/libio.h" 1 3 4
# 32 "/usr/include/libio.h" 3 4
# 1 "/usr/include/_G_config.h" 1 3 4
# 14 "/usr/include/_G_config.h" 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 1 3 4
# 326 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 3 4
# 355 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 3 4
# 15 "/usr/include/_G_config.h" 2 3 4
# 24 "/usr/include/_G_config.h" 3 4
# 1 "/usr/include/wchar.h" 1 3 4
# 48 "/usr/include/wchar.h" 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 1 3 4
# 49 "/usr/include/wchar.h" 2 3 4
# 1 "/usr/include/bits/wchar.h" 1 3 4
# 51 "/usr/include/wchar.h" 2 3 4
# 76 "/usr/include/wchar.h" 3 4
# 25 "/usr/include/_G_config.h" 2 3 4
# 44 "/usr/include/_G_config.h" 3 4
# 1 "/usr/include/gconv.h" 1 3 4
# 28 "/usr/include/gconv.h" 3 4
# 1 "/usr/include/wchar.h" 1 3 4
# 48 "/usr/include/wchar.h" 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 1 3 4
# 49 "/usr/include/wchar.h" 2 3 4
# 29 "/usr/include/gconv.h" 2 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h" 1 3 4
# 32 "/usr/include/gconv.h" 2 3 4
# 45 "/usr/include/_G_config.h" 2 3 4
# 33 "/usr/include/libio.h" 2 3 4
# 53 "/usr/include/libio.h" 3 4
# 1 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stdarg.h" 1 3 4
# 43 "/usr/lib/gcc/i586-suse-linux/4.2.1/include/stdarg.h" 3 4
# 54 "/usr/include/libio.h" 2 3 4
# 167 "/usr/include/libio.h" 3 4
# 177 "/usr/include/libio.h" 3 4
# 200 "/usr/include/libio.h" 3 4
# 268 "/usr/include/libio.h" 3 4
# 316 "/usr/include/libio.h" 3 4
# 325 "/usr/include/libio.h" 3 4
# 361 "/usr/include/libio.h" 3 4
# 413 "/usr/include/libio.h" 3 4
# 451 "/usr/include/libio.h" 3 4
# 481 "/usr/include/libio.h" 3 4
# 76 "/usr/include/stdio.h" 2 3 4
# 89 "/usr/include/stdio.h" 3 4
# 141 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/bits/stdio_lim.h" 1 3 4
# 142 "/usr/include/stdio.h" 2 3 4
# 188 "/usr/include/stdio.h" 3 4
# 206 "/usr/include/stdio.h" 3 4
# 231 "/usr/include/stdio.h" 3 4
# 245 "/usr/include/stdio.h" 3 4
# 274 "/usr/include/stdio.h" 3 4
# 285 "/usr/include/stdio.h" 3 4
# 306 "/usr/include/stdio.h" 3 4
# 400 "/usr/include/stdio.h" 3 4
# 442 "/usr/include/stdio.h" 3 4
# 466 "/usr/include/stdio.h" 3 4
# 477 "/usr/include/stdio.h" 3 4
# 510 "/usr/include/stdio.h" 3 4
# 591 "/usr/include/stdio.h" 3 4
# 644 "/usr/include/stdio.h" 3 4
# 680 "/usr/include/stdio.h" 3 4
# 699 "/usr/include/stdio.h" 3 4
# 722 "/usr/include/stdio.h" 3 4
# 731 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/bits/sys_errlist.h" 1 3 4
# 27 "/usr/include/bits/sys_errlist.h" 3 4
# 761 "/usr/include/stdio.h" 2 3 4
# 780 "/usr/include/stdio.h" 3 4
# 820 "/usr/include/stdio.h" 3 4
# 850 "/usr/include/stdio.h" 3 4
# 2 "curlies_return_value.c" 2
sergei@amdam2:~/junk>
Read "man cpp" for further info; you might need to use "gcc -E" instead of "cpp".
11-03-2008, 01:02 AM
#4
Member
Registered: Dec 2004
Posts: 92
Original Poster
Rep:
thanks for reply.
i know doxygen is powerfu, but it seems cost too much to generate all the include path while i only need trace one .h file.
gcc -E or cpp produce lots of output in my case, any tool available to parse them?
11-03-2008, 01:17 AM
#5
Member
Registered: Mar 2008
Posts: 183
Rep:
and... why can't you just do a grep for d.h on the header files?
11-03-2008, 03:28 AM
#6
Member
Registered: Dec 2004
Posts: 92
Original Poster
Rep:
sorry for my unclear expression.
I am not looking for path(/path/d.h),
but include relation trace like: a include b, b include c, c include d => a include d
11-03-2008, 04:51 AM
#7
Senior Member
Registered: May 2005
Posts: 4,481
Quote:
Originally Posted by
jackandking
thanks for reply.
i know doxygen is powerfu, but it seems cost too much to generate all the include path while i only need trace one .h file.
gcc -E or cpp produce lots of output in my case, any tool available to parse them?
It's UNIX, isn't it ?
Again:
Code:
cat -n curlies_return_value.c
1 #include <stdio.h>
2
3 int main()
4 {
5 int retval = ({int i = 1; int j = 2; i + j;});
6 printf("retval=%d\n", retval);
7 return 0;
8 }
Code:
cpp curlies_return_value.c | grep '#' | cut -d' ' -f3 | sort | uniq
"<built-in>"
"<command-line>"
"curlies_return_value.c"
"/usr/include/bits/stdio_lim.h"
"/usr/include/bits/sys_errlist.h"
"/usr/include/bits/types.h"
"/usr/include/bits/typesizes.h"
"/usr/include/bits/wchar.h"
"/usr/include/bits/wordsize.h"
"/usr/include/features.h"
"/usr/include/_G_config.h"
"/usr/include/gconv.h"
"/usr/include/gnu/stubs-32.h"
"/usr/include/gnu/stubs.h"
"/usr/include/libio.h"
"/usr/include/stdio.h"
"/usr/include/sys/cdefs.h"
"/usr/include/wchar.h"
"/usr/lib/gcc/i586-suse-linux/4.2.1/include/stdarg.h"
"/usr/lib/gcc/i586-suse-linux/4.2.1/include/stddef.h"
- pay attention to the added "| cut -d' ' -f3 | sort | uniq".
11-03-2008, 07:50 PM
#8
Member
Registered: Dec 2004
Posts: 92
Original Poster
Rep:
I get it, thanks a lot!
All times are GMT -5. The time now is 09:57 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News