Makefile工作%.c,不工作%.cpp [英] Makefile works %.c, does not work %.cpp

查看:130
本文介绍了Makefile工作%.c,不工作%.cpp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组makefile用于构建一个'大'C项目。

I have a set of makefiles I use to build a 'big' C project. I am now trying to reuse some in my C++ project and have run into this headache that I just cannot figure out.

makefile看起来像这样

The makefile looks like this

SOURCES = \
elements/blue.cpp

# Dont edit anything below here

VPATH = $(addprefix $(SOURCE_DIR)/, $(dir $(SOURCES)))

CXXFLAGS = $(OPT_FLAGS) -MMD -MF $(BUILD_DIR)/$*.d -D_LINUX -DNDEBUG -pipe
DCXXFLAGS = $(DEBUG_FLAGS) -MMD -MF $(BUILD_DIR)/$*.d -v -D_LINUX -D_DEBUG -pipe

OBJECTS := $(patsubst %.cpp, $(BUILD_DIR)/Release/%.o, $(notdir $(SOURCES)))
DOBJECTS := $(patsubst %.cpp, $(BUILD_DIR)/Debug/%.o, $(notdir $(SOURCES)))

$(OBJECTS): $(BUILD_DIR)/Release/%.o: %.cpp
    +@[ -d $(dir $@) ] || mkdir -p $(dir $@)
    $(CPP) $(INCLUDE) $(CXXFLAGS) $(DEFINES) -o $@ -c $<

它有点复杂,但它在C中做的是构建所有的%.c文件中定义的SOURCES并将对象文件放在BUILD_DIR中。它在c中工作伟大,但这不工作与cpp文件。我得到

Its a little complicated but what it does in C is build all the %.c files defined in SOURCES and put the object files in BUILD_DIR. It works great in c, but this does not work with cpp files. I get

make: *** No rule to make target `blue.cpp', needed by `build/Release/blue.o'.  Stop.

它像VPATH不工作。我尝试了

Its like VPATH is not working at all. I tried

vpath %.cpp src/elements

但这也不起作用。

令人惊讶的是,将blue.cpp重命名为blue.c并将makefile重新编译为%.c使用效果很好,它编译得很好。

Amazingly enough, renaming blue.cpp to blue.c and editing the makefile back to the %.c usage does work, it compiles just fine.

我在这里疯了吗?

推荐答案

Ok们我想出来了一个错误的大混乱。

Ok guys I figured it out here and its a big mess of a bug.

经过一些更多的实验后,我去修改bug列表上发布一个错误,并打开调试输出,告诉他们究竟发生了什么上。原来我应该这样做,因为它导致我的解决方案。

After some more experimentation I went to post a bug on the make-bugs list and turned on debug output to tell them exactly what was going on. Turns out I should have done this before because it led me right to the solution.

我使用自动依赖生成方案从 http://mad-scientist.net/make/autodep.html 和令人惊讶的是,打破了。此行出现问题

I use an automatic dependency generation scheme developed from http://mad-scientist.net/make/autodep.html and amazingly enough that was breaking make. Trouble occurred in with this line

-include $(patsubst %.c, $(BUILD_DIR)/%.d, $(notdir $(SOURCES)))



我没有将它改为%.cpp,包含blue.cpp导致make在尝试解析时不使用vpath搜索它

I did not change that to %.cpp and for some reason trying to include blue.cpp caused make to not search for it using vpath when it tried to resolve

$(OBJECTS): $(BUILD_DIR)/Release/%.o: %.cpp

所以解决方案只是移植makefile正确,doh!

So the solution was just to port the makefile correctly, doh!

这篇关于Makefile工作%.c,不工作%.cpp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆