发出文件警告,覆盖目标命令 [英] Make file warning, overriding commands for target

查看:56
本文介绍了发出文件警告,覆盖目标命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为生成文件的一部分,我想生成目标的调试版本或发布版本.

As part of the makefile i'd like to produce either a debug or release version of the target.

功能上一切正常,但是,运行make时我收到警告

Functionally, everything is working, however, i am getting warnings when running make

 12 SRC := $(shell echo src/*.cpp)
 13 SRC += $(shell echo $(TEST_ROOT)/*.cpp)
 14 
 15 D_OBJECTS = $(SRC:.cpp=.o)       # same objects will need to be built differently
 16 R_OBJECTS = $(SRC:.cpp=.o)       # same objects will need to be built differently

 22 all: $(TARGET)
 23 
 25 $(TARGET): $(D_OBJECTS)
 26   $(CC) $(D_OBJECTS) -o $(TARGET)
 27 
 28 $(D_OBJECTS) : %.o: %.cpp                     # ----- run with debug flags 
 29   $(CC) $(COMMON_FLAGS) $(DEBUG_FLAGS) -c $< -o $@
 30 
 31 release: $(R_OBJECTS)
 32   $(CC) $(R_OBJECTS) -o $(TARGET)
 33 
 34 $(R_OBJECTS) : %.o: %.cpp                     # ----- run with release flags
 35   $(CC) $(COMMON_FLAGS) $(RELEASE_FLAGS) -c $< -o $@

当我 make 获得调试版本时,当我 make release 获得发行版本.

When i make i get debug version, when i make release i get release version.

但我也收到警告:

Makefile:35: warning: overriding commands for target `src/Timer.o'
Makefile:29: warning: ignoring old commands for target `src/Timer.o'
Makefile:35: warning: overriding commands for target `test/TimerTest.o'
Makefile:29: warning: ignoring old commands for target `test/TimerTest.o'

有2个问题:

  1. 任何忽略警告的方式
  2. 我做对的事情对吗?需要进行哪些更改?

推荐答案

最常见的方法之一是将发布对象和调试对象放在单独的子目录中.这样,您就不会为对象的规则重新定义,因为它们将具有不同的名称.像这样:

One of the most common ways for doing this is to put the release objects and the debug objects in separate subdirectories. That way you don't get redefinitions for the rules for an object, since they will have different names. Something like this:

D_OBJECTS=$(SRC:%.cpp=debug/%.o)
R_OBJECTS=$(SRC:%.cpp=release/%.o)

RTARGET = a.out
DTARGET = a.out.debug

all : dirs $(RTARGET)

debug : dirs $(DTARGET)

dirs :
    @mkdir -p debug release

debug/%.o : %.c
    $(CC) $(DEBUG_CFLAGS) -o $@ -c $<

release/%.o : %.c
    $(CC) $(RELEASE_CFLAGS) -o $@ -c $<

$(DTARGET) : $(D_OBJECTS)
    $(CC) $(DEBUG_CFLAGS) -o $@ $(D_OBJECTS)

$(RTARGET) : $(R_OBJECTS)
    $(CC) $(RELEASE_CFLAGS) -o $@ $(R_OBJECTS)

这篇关于发出文件警告,覆盖目标命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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