This problem still exists in 2024. It's cause by different path names in the generated objects, the path used by eclipse and the path wanted by gdb.
When eclipse tries to set a breakpoint, it uses the absolute windows path to that file. Gdb compares that to the paths it got from the executable.
The message:
No source file named C:\Users\home\workspace\graphcpp\main.cpp.
means that in the executable is a different path.
If you are using CDT generated makefile then the paths are relative
../main.cpp
Since I found no working mapping setup, I switched from the generated makefile to my own Makefile and ensured that the files get compiled with the absolute path. To achieve this I'm using the make variable $(DIR)
DIR = $(subst \,/,$(PWD))
This variable is then used when an object gets compiled:
$(OUTDIR)/%.o: %.c Makefile $(HEADERS)
$(CC) -c $(LDFLAGS) $(CFLAGS) $(patsubst %,$(DIR)/%,$<) -o $@
$(OUTDIR)/%.o: %.cpp Makefile $(HEADERS)
$(C++) -c $(LDFLAGS) $(CFLAGS) $(C++FLAGS) $(patsubst %,$(DIR)/%,$<) -o
This results in object files having an absolute path usable by gdb
C:/Users/home/workspace/graphcpp/main.cpp
You may still need some mapping to locate the source files, but this can be achieved by using the Locate file button.
Here's my full Makefile
DIR = $(subst \,/,$(PWD))
TARGETS = test.exe
XTARGETS = $(patsubst %,$(OUTDIR)/%,$(TARGETS))
HEADERS = $(wildcard *.h)
SOURCES = $(wildcard *.c)
RESOURCES = $(wildcard *.rc)
OBJECTS = $(patsubst %.c,$(OUTDIR)/%.o,$(SOURCES)) $(patsubst %.rc,$(OUTDIR)/%.ro,$(RESOURCES))
LIBS = -luxtheme -lcomctl32 -lgdi32
CFLAGS = -g -O0
.PHONY: all pre
all: $(XTARGETS)
pre:
mkdir -p $(OUTDIR)
$(OUTDIR)/test.exe: pre $(OBJECTS)
gcc -o $@ $(OBJECTS) $(USER_OBJS) $(LIBS)
$(OUTDIR)/%.o: %.c Makefile $(HEADERS)
echo $(DIR)
$(CC) -c $(LDFLAGS) $(CFLAGS) $(C++FLAGS) $(patsubst %,$(DIR)/%,$<) -o $@
$(OUTDIR)/%.ro: %.rc Makefile $(HEADERS)
windres -O COFF $< -o $@
The variable $(OUTDIR) is set as custom build argument in the Eclipse C/C++ Build dialog of the project
OUTDIR=${ConfigName}
graphtemplate type come from?), but since the error seems not related to the contents of the file, all the graph stuff is distracting; I think a minimal code would be "int main() { /*line-break*/ return 0; /*line-break*/ }" and put a breakpoint on line "return 0;".int main() { /*line-break*/ return 0; /*line-break*/ }