LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 11-02-2008, 11:53 PM   #1
jackandking
Member
 
Registered: Dec 2004
Posts: 92

Rep: Reputation: 15
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!
 
Old 11-03-2008, 12:44 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
Old 11-03-2008, 12:54 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by jackandking View Post
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".
 
Old 11-03-2008, 01:02 AM   #4
jackandking
Member
 
Registered: Dec 2004
Posts: 92

Original Poster
Rep: Reputation: 15
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?
 
Old 11-03-2008, 01:17 AM   #5
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
and... why can't you just do a grep for d.h on the header files?
 
Old 11-03-2008, 03:28 AM   #6
jackandking
Member
 
Registered: Dec 2004
Posts: 92

Original Poster
Rep: Reputation: 15
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
 
Old 11-03-2008, 04:51 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by jackandking View Post
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".
 
Old 11-03-2008, 07:50 PM   #8
jackandking
Member
 
Registered: Dec 2004
Posts: 92

Original Poster
Rep: Reputation: 15
I get it, thanks a lot!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error compiling dosbox with "/usr/X11R6/include/GL/glu" hamster Linux - Software 4 11-08-2007 05:23 PM
Where "standard system include directory" is defined? (gcc) kaz2100 Programming 8 07-23-2006 08:22 AM
repeated message (tty1): ASSERT: "i <= nodes" in /usr/lib/qt-3.1.2/include/qvaluelist megahard Linux - General 4 01-17-2006 10:59 PM
Configuring Boot Process on Mandrake 10 to include command "ifup eith0" Bennyjamin Linux - Hardware 3 12-27-2004 04:22 PM
What is correct code for "Include File Function" on .asp pages gregoryfrancis Linux - General 1 02-11-2003 10:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration