How can I use gcc's -I command to add recursive folders

20,369

Solution 1

If you are using Apple's GCC (or Clang), then you can use the following approach (which appears to be an extension):


the parameter's suffix will need /**

-IMON_DIRECTORY/**

Now everything under MON_DIRECTORY/ may be searched.

Obviously, this could hurt your build times and it can result in inclusion of the wrong file when files have the same name. So... use it sparingly!

Solution 2

gcc has various ways to control the include search path, but I see nothing providing what you want. Note that you can use environment variables for that, it could be more convenient for you than the alternatives.

Share:
20,369

Related videos on Youtube

shengy
Author by

shengy

Likes: C/C++, Go, Python, git, vim, linux, mac

Updated on July 25, 2022

Comments

  • shengy
    shengy almost 2 years

    Is there a way to use gcc's -I command and add all the paths to search path by giving a root directory?

    I'm trying to use :!gcc -E myfile.c to view macro expansions, but myfile.c includes a whole bunch of other header files in different directories, and because I'm executing this command in vim, so I don't want to call a makefile, is there anyway to do this?

  • shengy
    shengy over 11 years
    C:\Documents and Settings\nzwqv9\Desktop\New Folder\** is my root folder, and gcc -I "C:\Documents and Settings\nzwqv9\Desktop\New Folder\**" -E test.c is still not finding the header file...
  • themel
    themel over 11 years
    I'm unable to reproduce as well.
  • justin
    justin over 11 years
    @shengy try gcc "-IC:\Documents and Settings\nzwqv9\Desktop\New Folder\**" -E test.c instead.
  • AProgrammer
    AProgrammer over 11 years
    That looks like globbing, my guess is that it's a zsh feature, not a gcc one.
  • justin
    justin over 11 years
    @AProgrammer i don't use recursive discovery - builds take long enough! this does work on my system - but i am beginning to think it may be an Apple-GCC extension.
  • shengy
    shengy over 11 years
    @justin Still not working, I hate using gcc under windows.... it always messup with the slash or something else...
  • justin
    justin over 11 years
    @shengy alright - i will assume this is an Apple-GCC extension, and update the answer. sorry about that.
  • shengy
    shengy over 11 years
    @justin :) maybe it's just because I didn't use it the right way. I'll comment here as soon as I got the solution.