【发布时间】:2013-07-20 01:06:46
【问题描述】:
也许我做错了什么,但是当 makefile 看起来像这样时,make 拒绝检查依赖项的时间戳。
# This makefile won't update the objects if you modify the .cpp files
# and it will only create them if they do not exist.
CC=g++
FL=-g
OBJECTD=../obj
SOURCED=../src
# Get all .cpp files in ../src
SOURCES=$(wildcard *.cpp)
# Convert .cpp to .o then add ../obj in front
OBJECTS=$(addprefix $(OBJECTD)/,$(patsubst %.cpp,%.o,$(SOURCES)))
# You sir must execute yourself whether you like it or not
.PHONY:all
all:$(OBJECTS)
@echo : Leaving `src`
# This wont work as expected ...
# @echo : Compiling $(notdir $(patsubst %.o,%.cpp,$@))
# echoes Compiling logger.cpp
# But $(notdir $(patsubst %.o,%.cpp,$@)) will not be parsed
# correctly
$(OBJECTS):$(notdir $(patsubst %.o,%.cpp,$@))
@echo : Compiling $(notdir $(patsubst %.o,%.cpp,$@))
@$(CC) $(FL) -c $(notdir $(patsubst %.o,%.cpp,$@)) -o $@
我相信它不会接受$(notdir $(patsubst %.o,%.cpp,$@))
即使文档声明
在具有多个目标的模式规则中(请参阅模式规则简介),'$@' 是导致规则的目标的名称 要运行的配方。
分别对每个文件进行编译,效果很好。
例如:
../obj/logger.o:logger.cpp
@echo : Compiling $<
@$(CC) $(FL) -c $< -o $@
+------------+
: 额外信息:
+------------+
我想要实现的是从当前目录读取源代码,检查它们是否已更改,然后继续编译它们,同时将对象放在 ../obj 而不是当前目录。
这是位于 ../src 中的makefile,在父目录中还有一个用于链接。
我想要处理的结构的图形表示
+--- Parent Directory ------+
| | | |
| | | |
bin obj inc src
【问题讨论】:
标签: c++ recursion makefile gnu