[Debug] How to debug with single makefile?

Answered

Hi everyone. 

I have a current assignment with provide with only a makefile.

But I want to use our CLion, and add a single CMakeList.txt to call the provided makefile.

This approach let me be able to build and run this project in our CLion.

But if I set some breakpoints and want to debug. The program runs as normally build/run, and ignores the breakpoints and ends.

I just want to ask how to make this situation debug possible?

 

==================================

provided makefile: 

CC=g++  ## added
TARGET=moep
LDFLAGS=
## CFLAGS+=-Wall -Wextra -fdiagnostics-color=auto
CXXFLAGS+=-Wall -Wextra -fdiagnostics-color=auto
BUILDDIR=build
 
OBJECTS=build/arguments.o build/assignment1.o
 
.PHONY: all clean fresh
 
all: $(TARGET)
 
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)
 
## $(BUILDDIR)/%.o: src/%.c $(BUILDDIR)
$(BUILDDIR)/%.o: src/%.cpp $(BUILDDIR)
$(CC) $(CFLAGS) $< -c -o $@
 
$(BUILDDIR):
mkdir $(BUILDDIR)
 
clean:
-rm -rf $(BUILDDIR)
-rm -f $(TARGET)
 
fresh: clean all
 
 
 
my added CMakeLists.txt
 
cmake_minimum_required(VERSION 2.8.4)
project(assignment1)
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES ./)
 
add_custom_target(assignment1 COMMAND make -C ${mytest_SOURCE_DIR}
        CLION_EXE_DIR=${PROJECT_BINARY_DIR})
 
 

 

 

1
2 comments
Avatar
Permanently deleted user

1

Hello! You can either convert your project into a proper CMake-based project (add target etc.), or open your project using Compilation Database (https://blog.jetbrains.com/clion/2018/08/working-with-makefiles-in-clion-using-compilation-db/) and use custom build targets and applications (https://www.jetbrains.com/help/clion/2019.1/custom-build-targets.html) to build and run/debug.

1

Please sign in to leave a comment.