Creating files breaks -DDEBUG flag in Makefile for C++

时间:2015-05-12 22:57:12

标签: c++ compilation makefile linker

In my Makefile I am using the -DDEBUG Flag for debugging which works fine (compiles and right output) in the following minimal example:

function get_dates(){
 var result = $("#c1").calendar('getDate').format();
 $('#ExpectedDatetimeStamp').val(result)
}

$('.cell').closest('form').submit(function(){
 //..any other values that need to be populated
 get_dates();
});

But when i copy all project-files into the Folder the Debug-Flag wont be set (tested with #ifdef DEBUG and cout). I am adding the following files:

# Makefile
all : debug

CXX = g++
CXXFLAGS = -std=c++11 -Werror -Wall -Wextra -Wno-unused-value
SOURCES = main.cpp vector.cpp
OBJECTS = $(subst .cpp,.o, $(SOURCES))

debug: $(OBJECTS)
    $(CXX) $(CXXFLAGS) -DDEBUG -o Program $(OBJECTS)
    ./Program

clean:
    rm *.o Program

.PHONY: clean debug

I first thought debug.* could be the problem, but ".PHONY: clean debug" didn't help.

1 个答案:

答案 0 :(得分:2)

Makefile更改此内容:

debug: $(OBJECTS)
    $(CXX) $(CXXFLAGS) -DDEBUG -o Program $(OBJECTS)

为:

debug: $(SOURCES)
    $(CXX) $(CXXFLAGS) -DDEBUG -o Program $(SOURCES)

原因是,在构建debug目标的规则中,您只有linking个目标文件而不是compiling -DDEBUG。通过此更改,您应该能够使用-DDEBUG标志进行编译。