Mac Clion 2019.01 Makefile use single-step debugging

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/tanningzhong/article/details/89083813

Mac Clion 2019.01 Makefile use single-step debugging

Installation Clion

slightly

Clion use single-step debugging

MakeFile plug-in installation

在File>>setting>>plugins>>makefile support>>install安装,As shown below:
Here Insert Picture Description

Compile Debugging

After installing the plug-in, write good Makefile file, select the Makefile right, select run Makefile, as shown below:
Here Insert Picture Description

3 behind that I just run a few times Makefile generated automatically, do not need to ignore. Normally the output window will compile information.

Select the menu, Run >> Debug, and then select the configuration
Here Insert Picture Description
Here Insert Picture Description

Add CMakeLists file

cmake_minimum_required(VERSION 3.12)
project(test)

set(CMAKE_CXX_STANDARD 11)
set(BUILD_DIR ${PROJECT_SOURCE_DIR})  #设置编译目录,也就是Makefile文件所在目录
message(${BUILD_DIR}) #打印目录路径
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_custom_target(test COMMAND make -C ${BUILD_DIR}) #最关键的就是这句, 设置外部编译文件而不是使用CMakeLists.txt

The last break point to debug.

Here Insert Picture Description
Here Insert Picture Description

Appendix Test Demo

### test.c
#include <stdio.h>
int main(void)
{
    int a = 3;
    int b = 2;
        
    printf("a=%d\n", a);
    printf("b=%d\n", b);
    
    printf("a+b=%d\n", add(a,b));
    printf("a-b=%d\n", sub(a,b));
    return 0;
}


### test-add.c
int add(int a, int b) 
{
    return a+b;
}

### test-sub.c
int sub(int a, int b) 
{
    return a-b;
}

### Makefile
# 指令编译器和选项,-g一定需要加上,否则无法调试
CC=gcc
CFLAGS=-Wall -std=gnu99 -g
 
# 目标文件
TARGET=test
# 源文件
SRCS=test.c test-add.c test-sub.c
 
OBJS = $(SRCS:.c=.o)
 
$(TARGET):$(OBJS)
#	@echo TARGET:$@
#	@echo OBJECTS:$^
	$(CC) -o $@ $^
 
clean:
	rm -rf $(TARGET) $(OBJS)
 
%.o:%.c
	$(CC) $(CFLAGS) -o $@ -c $<

Guess you like

Origin blog.csdn.net/tanningzhong/article/details/89083813