Can I search directory and subdirectories for header files?

后端 未结 1 2083
一生所求
一生所求 2021-02-20 13:01

Is is possible to instruct g++ to search a folder recursively for header files? In my example I would like g++ to search

相关标签:
1条回答
  • 2021-02-20 13:18

    The question is a little confusing because you're conflating two different tools, make and g++.

    There is no way to get g++ search all subdirectories of a given directory. Every directory you want to use to find an included file must be individually specified on the command line with a -I flag.

    If you want to, you can get make to construct those arguments and put them on your command line. Assuming you're using GNU make, and a UNIX-like system that supports the find command, you can do something like this:

    INCDIRS := $(addprefix -I,$(shell find /ARDrone_SDK_2_0_1/ARDroneLib/Soft -type d -print))
    

    I should just say up-front, this is not really a good idea. You don't know what order those directories will show up in, and you don't know if there are multiple copies of the same header file in different directories that might cause problems.

    Generally the way headers in subdirectories are expected to work is that you add the top-level directory to the compile line, then use relative paths in the #include line in your code. Something like:

    #include <subdir/subsubdir/header.h>
    

    Then add:

    -I/top/level/dir
    

    to the g++ compile line.

    0 讨论(0)
提交回复
热议问题