English 中文(简体)
档案改善,抚养人不能发挥作用
原标题:Makefile improvements, dependency generation not functioning

我目前正在尝试建立一个适当的马克图案。

我想的是完全控制所发生的事情,因此我不想使用第三方软件。

我目前的尝试看来是逻辑的,但由于依赖性一代不是有效的,我不喜欢。

读写能力越好,全书就破碎。 如果有任何改进之处,我将不胜感激。

首先,我有以下固定定义:

CXX = g++
CXXFLAGS = -Wall 
           -Wextra 
           -Wuninitialized 
           -Wmissing-declarations 
           -pedantic 
           -O3 
           -p -g -pg
LDFLAGS =  -p -g -pg
DEPFLAGS = -MM

Afaik 这应当罚款。 最好使貌相标志成为选择性的标志,但这并非重要。

SRC_DIR = ./src
OBJ_DIR = ./obj
SRC_EXT = .cpp
OBJ_EXT = .o

TARGET = ./bin/my_target

SRCS = $(wildcard $(SRC_DIR)/*$(SRC_EXT))
OBJS = $(subst $(SRC_DIR), $(OBJ_DIR), $(SRCS:$(SRC_EXT)=$(OBJ_EXT)))
DEP = depend.main

基本上,这应当只是从以下各分册中提取所有<代码>*.cpp的文档,并再以<代码>取代<代码>/src。

.PHONY: clean all depend

all: $(TARGET)

$(TARGET): $(OBJS)
    @echo "-> linking $@"
    @$(CXX) $^ $(LDFLAGS) -o $@

$(OBJ_DIR)/%.$(EXT_OBJ):
    @echo "-> compiling $@"
    @$(CXX) $(CXXFLAGS) -c $< -o $@

Afaik,这个区块——只要有有效的附属档案,就应当进行一切必要的汇编和连接。

clean:
    @echo "removing objects and main file"
    @rm -f $(OBJS) $(TARGET)    

难道应该自我解释和正确,或者我在这里没有东西?

$(SRC_DIR)/%.$(SRC_EXT): 
    $(CXX) $(DEPFLAGS) -MT 
    "$(subst $(SRC_DIR),$(OBJ_DIR),$(subst $(SRC_EXT),$(OBJ_EXT),$@))" 
    $(addprefix ,$@) >> $(DEP);

clear_dependencies:
    @echo "-> (re-)building dependencies";
    @$(RM) $(DEP)

depend: clear_dependencies $(SRCS)

This is the non-functional part. What I intend to do is using the g++ Compiler flag -MM to auto-create dependencies and using -MT to use a different path than the default one. The resulting dependency should look like

./obj/main.o: ./src/main.cpp ./src/some_header_file.h

Unfortunately, this will never be called and I lack the knowledge why this is the case. In a similar question, user Beta gladly provided a temporary solution by adding a .Phony but this has the side effect on rebuilding every object without any change.

最后,只有一个线。

-include $(DEP)

包括扶养档案,一旦建立。

Any answer providing some hints about any part are very welcome. So my question is: What can I do better or maybe "cleaner" and why doesn t the dependency generation work?

最佳回答

这里是这样。


Assign simply supplemented 变量 在可能的情况下:

SRCS := $(wildcard $(SRC_DIR)/*$(SRC_EXT))

http://www.gnu.org/software/make/manual/make.html#Flavors”rel=“noreferer” • 手册:

Another disadvantage [of recursively expanded variables] is that any functions referenced in the definition will be executed every time the variable is expanded. This makes make run slower; worse, it causes the wildcard and shell functions to give unpredictable results because you cannot easily control when they are called, or even how many times.


http://www.gnu.org/software/make/manual/make.html#Substitution-Refs” rel=“noreferer”>substitution参引文件patsubst=<>=将来源转化为物体:

OBJS := $(SRCS:$(SRC_DIR)/%$(SRC_EXT)=$(OBJ_DIR)/%$(OBJ_EXT))

具体说明汇编模式规则的适当先决条件。 这是mandatory,以更新贵国的物体档案并更新其来源变化。

$(OBJ_DIR)/%$(OBJ_EXT) : $(SRC_DIR)/%$(SRC_EXT)
    @echo "-> compiling $@"
    @$(CXX) $(CXXFLAGS) -o $@ -c $<

收集来源,同时为它们编制扶养档案。 使用<条码>-MMD -MP 旗帜,以便做事(将其附在上)。

CXXFLAGS += -MMD -MP

-include $(OBJS:$(OBJ_EXT)=.d)

http://gcc.gnu.org

-MD

-MD is equivalent to -M -MF file, except that -E is not implied. The driver determines file based on whether an -o option is given. If it is, the driver uses its argument but with a suffix of .d, otherwise it takes the name of the input file, removes any directory components and suffix, and applies a .d suffix.

-MD 仅提及用户负责人档案,而不是系统负责人档案。

-MP

这一办法指示民防部队在主要档案之外增加每个受抚养人的电话目标,使每个受抚养人都无从依赖。 如果你在不更新<代码>Makefile的情况下删除标题档案,则这些定律规则围绕错误开展工作。

Also consider studying this article of Paul Smith (he is a maintainer of GNU Make). It gives a rather good overview of different autodep-generation approaches.

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签