Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

c++ - Build Eclipse Makefile project from command line

I have created Eclipse Makefile c++ project with intention to build project also without Eclipse. But I got error while run make in terminal:

Makefile:15: *** Build mode  not supported by this Makefile.  Stop.

How to fix that? Why I should need Eclipse Makefile if I can't build it with make?

Makefile content:

PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

OBJS = boiler.o

ifeq ($(BUILD_MODE),debug)
    CFLAGS += -g
else ifeq ($(BUILD_MODE),profile)
    CFLAGS += -O2
else ifeq ($(BUILD_MODE),run)
    CFLAGS += -O2
else ifeq ($(BUILD_MODE),linuxtools)
    CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
    LDFLAGS += -pg -fprofile-arcs -ftest-coverage
else
    $(error Build mode $(BUILD_MODE) not supported by this Makefile)
endif

all:    boiler

boiler: $(OBJS)
    $(CXX) $(LDFLAGS) -o $@ $^

%.o:    $(PROJECT_ROOT)%.cpp
    $(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -o $@ $<

%.o:    $(PROJECT_ROOT)%.c
    $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<

clean:
    rm -fr boiler $(OBJS)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm not sure exactly how you created your Makefile ...

... but the problem is clearly that your Makefile happens to rely on the variable "$(BUILD_MODE)" ...

... and, the way you're running "make", BUILD_MODE isn't being set to one of your options, or isn't being set at all.

SUGGESTION: Type this on the command line: make BUILD_MODE=debug

PS:

  • Equivalently, you could define BUILD_MODE as an environment variable, e.g. set BUILD_MODE=debug (DOS prompt) or export BUILD_MODE-debug (Linux term)
  • "BUILD_MODE" isn't "required". It's just a convention. That your "Makefile generator" happened to add when it created your particular makefile.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...