在eclipse中调试makefile项目

时间:2011-12-29 02:10:23

标签: c++ eclipse eclipse-cdt

我在eclipse中导入了“现有代码作为makefile项目”项目。 我想在eclipse中调试,比如我可以创建断点或者单步执行代码。 如果我直接调试项目,eclipse说XXX.cpp没有源代码,所以我无法调试。

如何在eclipse中将makefile更改为debug?

1 个答案:

答案 0 :(得分:12)

只需确保您的Makefile目标不会删除可执行文件,它包含调试符号。

这意味着gcc行不得包含-s,并且应包含-g

这种简单Makefile的一个例子是:

TARGET   = YOUR_EXECUTABLE_NAME
SOURCES  = $(shell echo *.c)
HEADERS  = $(shell echo *.h)

prefix   = /usr/local
bindir   = $(prefix)/bin

all: $(TARGET)

debug: CFLAGS += -g -O0 -Wall -Wextra
debug: $(TARGET)

$(TARGET): $(SOURCES) $(HEADERS)
    $(CC) $(CFLAGS) $(DEFS) -o $(TARGET) $(SOURCES) $(LIBS)

install: $(TARGET)
    install -s -D $(TARGET) $(DESTDIR)$(bindir)/$(TARGET)

uninstall:
    rm -f $(DESTDIR)$(bindir)/$(TARGET)

clean:
    rm -f $(TARGET)

distclean: clean

.PHONY : all debug install uninstall clean distclean