gpt4 book ai didi

c++ - makefile 依赖于特定目录中的所有文件

转载 作者:行者123 更新时间:2023-11-28 05:37:30 25 4
gpt4 key购买 nike

我有一个 C++ 项目。在我的项目文件夹中,我有三个子项目文件夹。

Proj_Folder
Include
head1.h
head2.h
....
Sub_Proj1
proj1.cpp
makefile
Sub_Proj2
proj2.cpp
makefile
Sub_Proj3
proj3.cpp
makefile
ShareAll.cpp
makefile

这是“Proj_Folder”文件夹中的 makefile。

OBJS =  ../ShareAll.o proj1.o

proj1: ${OBJS}
${CXX} ${CFLAGS} -o $@ $+

proj1.o : proj1.cpp
${CXX} ${CFLAGS} -c $< -o $@

../ShareAll.o : ../ShareAll.cpp
${CXX} ${CFLAGS} -c $< -o $@

我需要包含位于“Include”目录中的所有头文件作为整个项目的依赖项。

我试过下面的代码。

C_HEADER_FILES := $(patsubst Include/*.h)

# The dependency file names.
DEPS := $(C_HEADER_FILES:.h=.d)

# Let make read the dependency files and handle them.
-include $(DEPS)

但是它说,

makefile:30: *** insufficient number of arguments (1) to function `patsubst'.  Stop.

如何将所有头文件作为依赖项包含在此项目 makefile 中?

最佳答案

您使用了错误的函数来收集 .h 文件集。您需要使用:

C_HEADER_FILES := $(wildcard Include/*.h)

关于c++ - makefile 依赖于特定目录中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com