0

我正在尝试为项目创建调试和发布配置,但我无法弄清楚出了什么问题。

出于某种原因,当我执行“make debug”时,make 会跳过“all”的依赖项,给我一堆来自 g++ 的错误(没有这样的文件或目录)。更奇怪的是,如果我“全力以赴”,一切都会很好。

这是生成文件:

SHELL=/bin/sh
CXX=g++
LIBS=-LE:\Software\StrategyEngine\Release -llibdebug
CFLAGS=-Wall -O3 -IE:\Software\StrategyEngine\include

BDIR=Build\Release

debug: CFLAGS+=-g -DDEBUG
debug: LIBS=-LE:\Software\StrategyEngine\Debug -llibdebug
debug: BDIR=Build\Debug

OBJS= $(BDIR)\blocksort.o  \
      #... more object files
      $(BDIR)\CompressionStream.o

debug: all

all: $(OBJS) 
    $(CXX) $(LIBS) -shared -o $(BDIR)\libbz2.dll $(OBJS)
    $(CXX) $(LIBS) $(CFLAGS) -o $(BDIR)\bzip2-shared bzip2.cpp $(BDIR)\libbz2.dll

$(BDIR)\blocksort.o: blocksort.cpp
    $(CXX) $(CFLAGS) -c blocksort.cpp -o $(BDIR)\blocksort.o
#.... more rules for each object file defined in OBJS

clean: 
    rm -f Build\debug\* Build\release\*

为什么会这样?我在makefile中找不到任何错误。

我正在使用在 Windows 7 上运行的 mingw 编译器套件(make 版本 3.81)。

4

1 回答 1

2

makefile 中的目标文件位置BDIR不会根据构建模式而改变。

我建议重构脚本如下:

SHELL=/bin/sh
CXX=g++

BUILD := debug # default mode

CFLAGS.release := -Wall -O3 -IE:/Software/StrategyEngine/include -D_NDEBUG
CFLAGS.debug   := -Wall -g  -IE:/Software/StrategyEngine/include -DDEBUG
LIBS.release := -LE:/Software/StrategyEngine/Release -llibdebug
LIBS.debug   := -LE:/Software/StrategyEngine/Debug -llibdebug
BDIR.release := Build/Release
BDIR.debug   := Build/Debug

CFLAGS := ${CFLAGS.${BUILD}}
LIBS := ${LIBS.${BUILD}}
BDIR := ${BDIR.${BUILD}}

OBJS= $(BDIR)/blocksort.o  /
      #... more object files
      $(BDIR)/CompressionStream.o

all: $(OBJS)
    $(CXX) $(LIBS) -shared -o $(BDIR)/libbz2.dll $(OBJS)
    $(CXX) $(LIBS) $(CFLAGS) -o $(BDIR)/bzip2-shared bzip2.cpp $(BDIR)/libbz2.dll

$(BDIR)/blocksort.o: blocksort.cpp
    $(CXX) $(CFLAGS) -c blocksort.cpp -o $(BDIR)/blocksort.o
#.... more rules for each object file defined in OBJS

clean:
    rm -f Build/debug/* Build/release/*

.PHONY: all clean 

并像这样使用它:

make BUILD=debug
make BUILD=release
于 2012-07-17T10:56:17.690 回答