LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Recursively include headers in include option for gcc (http://www.linuxquestions.org/questions/linux-newbie-8/recursively-include-headers-in-include-option-for-gcc-763234/)

kvm1983 10-20-2009 12:14 PM

Recursively include headers in include option for gcc
 
Hello all,
Is there a way to recursively include all header files in the gcc command
"cc -I ..."

I have a directory with tens of subdirectories, each of which have header files in them. So while compiling a program test.c, I have a very long cc command like
"cc -I /home/dir/subdir1 -I /home/dir/subdir2 -I /home/dir/subdir3 ..... test.c"

If there could be a way to recursively include all header files in a directory, the compilation command would be pretty short in length.

Thanks,
Kshitij

smeezekitty 10-20-2009 06:14 PM

AFAIK you cannot do it with GCC alone

knudfl 10-21-2009 04:07 PM

"cc -I ..." is OK.
The alternative is a Makefile.

This example is a snippet from ns-2.33/Makefile.in
Code:

    63       
    64        INCLUDES = \
    65                -I. @V_INCLUDE_X11@ \
    66                -I. \
    67                @V_INCLUDES@ \
    68                -I./tcp -I./sctp -I./common -I./link -I./queue \
    69                -I./adc -I./apps -I./mac -I./mobile -I./trace \
    70                -I./routing -I./tools -I./classifier -I./mcast \
    71                -I./diffusion3/lib/main -I./diffusion3/lib \
    72                -I./diffusion3/lib/nr -I./diffusion3/ns \
    73                -I./diffusion3/filter_core -I./asim/ -I./qs \
    74                -I./diffserv -I./satellite \
    75                -I./wpan
    76


mischasan 09-04-2012 02:56 PM

The shell is your friend; and your "-I" options are being used in a shell command invoking gcc.
So it is totally legit:
INCLUDE = ..... \
`find /home/dir/subdir[12345] -type d | sed s/^/-I/` # note the (`) backquotes

smeezekitty 09-04-2012 02:58 PM

Quote:

Originally Posted by mischasan (Post 4772619)
The shell is your friend; and your "-I" options are being used in a shell command invoking gcc.
So it is totally legit:
INCLUDE = ..... \
`find /home/dir/subdir[12345] -type d | sed s/^/-I/` # note the (`) backquotes

This thread is three years old...

mischasan 09-04-2012 03:21 PM

Yah, I guess I have too much time on my hands ... and the post showed up in google search, ABOVE one of my own blog posts on a related topic.


All times are GMT -5. The time now is 05:57 AM.