[英]Makefile for automatic placement of object and dependency file in separate folder
I would like to place the object files of the compiler in a different folder than the source files. 我想将编译器的目标文件放在与源文件不同的文件夹中。 I made it working, when using the same folder structure as the way my source code is build up, but this is not the solution i am looking for.
当使用与我的源代码构建方式相同的文件夹结构时,它可以正常工作,但这不是我正在寻找的解决方案。
What I would prefer is the following: 我希望以下是:
Sources: 资料来源:
src/main.cpp
src/myClass/myClass.cpp
Object: 宾语:
obj/main.o
obj/myClass.o
Dependencies 依存关系
dep/main.d
dep/main.d
What I have until now is the following 我到目前为止所拥有的是以下内容
VARIABLES 变数
$(OBJLIST)=obj/main.o obj/myClass.o
$(SRCDIR)=src
$(OBJDIR)=obj
LINKER 链接器
$(PROJECT): $(OBJLIST)
$(CXX) $(OBJLIST) $(LIBS) -o $@
COMPILER and here is my problem 编译器,这是我的问题
This is what is working 这是起作用的
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(DEPDIR) $(OBJDIR)
$(CXX) $(CPPFLAGS) -c $< -o $@
$(CXX) $(CPPFLAGS) -MM -MT 1_obj/main.o 0_src/main.cpp -o 2_dep/main.dep
$(OBJDIR)/%.o: $(SRCDIR)/myClass/%.cpp
@mkdir -p $(DEPDIR) $(OBJDIR)
$(CXX) $(CPPFLAGS) -c $< -o $@
$(CXX) $(CPPFLAGS) -MM -MT 1_obj/myClass.o 0_src/myClass/myClass.cpp -o 2_dep/myClass.dep
I also have an object called SRCDIRS containing: 我还有一个名为SRCDIRS的对象,其中包含:
SRCDIRS
./
./myClass
So i hoped I could merge the compile-definitions to something like 所以我希望我可以将编译定义合并到类似
$(OBJDIR)/%.o: $(SRCDIR)/$(SRCDIRS)/%.cpp
@mkdir -p $(DEPDIR) $(OBJDIR)
$(CXX) $(CPPFLAGS) -c $< -o $@
$(CXX) $(CPPFLAGS) -MM -MT $@ @< -o $(DEPDIR)/$(notdir $(basename $<).dep)
I hoped this would generalize for both possibilities, but somehow, it seams it does not loop through SRCDIRS and check for any match. 我希望这可以同时适用于这两种可能性,但是不知何故,它接缝不会在SRCDIRS中循环并检查是否匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.