简体   繁体   中英

Breakpoints ignored in Xcode when using Makefile to build

I'm trying to set up an C++ project in Xcode that uses a Makefile to build.

I got it working by starting with a completely empty project (Empty template), adding an External Build System target and setting up the paths correctly:

在此输入图像描述

However breakpoints don't work. I created a very simple test project with a single .cpp file, but no matter what I try, the breakpoint is ignored:

在此输入图像描述

As suggested in an other question , I tried to go to Product -> Edit Scheme... and check 'use custom working directory' and I set this to the same directory as the executable, but it didn't help.

All my files (source, makefile, executable, project file) are in a single folder in Finder (and in Xcode too).

If it matters my Makefile is very simple too:

BUILD = .
TARGET = $(BUILD)/test
all:
    g++  test.cpp  -o $(TARGET)

Add -g switch to the gcc command to include debugging symbols like this:

BUILD = .
TARGET = $(BUILD)/test
all:
    g++ -g test.cpp  -o $(TARGET)

EDIT: And chose another target name because test is a shell built-in command in most shells and you might run into trouble invoking your program from the command line (even if I'm not sure about Mac OS).

I had the same problem (Xcode 8.3.3) but adding -g to the makefile did not fix it. I discovered (after much pain) that the makefile was cleaning up the .o files as part of the build (rm -f $(OBJFILES)). It turns out the symbol information resides in the .o files so by deleting them Xcode could no longer debug. I commented out the rm line and everything now works. I used the -g flag and it works. Anyone battling this should make sure the .o files are around in the proper location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM