简体   繁体   English

如何在我的Makefile中包含目录及其所有子目录的标题?

[英]How can I include headers from a directory and all its subdirectories in my makefile?

My project organization is as follows: 我的项目组织如下:

  • Makefile 生成文件
  • build 建立
    • objects 对象
    • apps 应用
  • include 包括
    • subdirectory (contains *.h) 子目录(包含* .h)
    • subdirectory (contains *.h) 子目录(包含* .h)
  • src src
    • subdirectory (contains *.cpp) 子目录(包含* .cpp)
    • subdirectory (contains *.cpp) 子目录(包含* .cpp)

In my makefile, to grab all *.h from the subdirectories I currently use: 在我的makefile中,从我当前使用的子目录中获取所有* .h:

#includes (.h / .hpp)
INC_DIRS := \
$(wildcard include/*/)

INCLUDE = $(foreach d, $(INC_DIRS), -I$d)

This does work, and I am able to compile fine. 确实有效,并且我能够编译良好。 However I was wondering if there was a simpler way to include all subdirectories in a single include statement. 但是我想知道是否有更简单的方法将所有子目录包含在单个include语句中。

The current method I am using does a '-Iinclude/subdirectory' for each subdirectory and it looks really messy and confusing in the terminal. 我正在使用的当前方法对每个子目录都执行“ -Iinclude / subdirectory”,并且在终端中看起来非常混乱和混乱。

Given your include path approach, this is a good way to specify it in your makefile. 考虑到您的包含路径方法,这是在makefile中指定它的好方法。

However, it would be better to not require all these subdirectories to be in the path, and instead use relative paths inside your code. 但是,最好不要将所有这些子目录都放在路径中,而应在代码内使用相对路径。

#include "somedir/thing.h"
#include "somedir2/otherthing.h"

and so forth. 等等。

This will also then be much easier to port to other build systems if needed. 如果需要,这也将更容易移植到其他构建系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM