【发布时间】:2021-05-10 16:28:56
【问题描述】:
我有这个布局:
project/
Makefile
core/
a.cpp
a.hpp
utl/
b.cpp
b.hpp
obj/
我想将所有 .o 文件放在 obj 文件夹中,这样我就可以从这些目标文件中创建一个共享库。但由于我的 .cpp 文件位于不同的目录中,我不知道如何自动执行此操作。不仅有这两个目录,还有多个目录。任何提示表示赞赏。
我的尝试失败了,因为我假设 .o 的自动规则(我想使用)希望 .cpp 位于 .o 应该在的同一目录中?
# grab all cpp files with their path that are in some DIRS list
SRC = $(wildcard *.cpp) $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.cpp))
# remove the path
SRC_WITHOUT_PATH = $(notdir $(SRC))
# stick the .obj/ directory before the .cpp file and change the extension
OBJ = $(SRC_WITHOUT_PATH:%.cpp=./obj/%.o)
# error is no rule to make target obj/a.o
【问题讨论】:
标签: makefile compilation shared-libraries project gnu-make