Home > database >  Debug C program using makefile on vscode (mac M1)
Debug C program using makefile on vscode (mac M1)

Time:07-14

I just split up my one file c project into a multiple file project and was trying to debug it leveraging my makefile. I tried to follow some tutorials but I could never replicate the results. I don't know if it is my incompetence or the fact that I'm using a M1 mac.

(Please note that I am new to programming and get very confused with the differences between gcc, clang, lldb and gdb)

My makefile

CC=gcc

CFLAGS=-Wall -Wextra -Werror -g

MLX=mlx/libmlx_Darwin.a

LIBFT=libft/libft.a

I_LIBFT=-Ilibft -Llibft -lft

I_LIBMLX=-Imlx -Lmlx -lmlx

LIB=$(I_LIBFT) $(I_LIBMLX)

COMPATIBILITY=-lX11 -lXext

FRAMEWORK=-framework OpenGL -framework AppKit

HDR=-Iinclude

LIBHDR=-Ilibft -Imlx

SRC_DIR=src/

SRCS:=$(wildcard $(SRC_DIR)*.c)

OBJ_DIR=obj/

OBJS=$(patsubst $(SRC_DIR)%.c, $(OBJ_DIR)%.o, $(SRCS))

all: $(LIBFT) app

$(LIBFT):
    make -C libft
    @echo "done libft"

$(OBJ_DIR):
    mkdir $@
 
$(OBJS): $(OBJ_DIR)%.o: $(SRC_DIR)%.c $(OBJ_DIR)
    $(CC) $(CFLAGS) $(HDR) $(LIBHDR) -c $< -o $@ 

app: $(OBJS)
    @echo "making app"
    $(CC) $(CFLAGS) $(LIB) $(FRAMEWORK) $(OBJS) -o FdF

clean:
    make -C libft $@

fclean: clean
    make -C libft $@

re: fclean all

.PHONY: all clean fclean re so

My launch.JSON:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/FdF/FdF",
            "args": ["test_maps/julia.fdf"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/FdF",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "${workspaceFolder}/FdF/FdF",
        }
    ],
}

My file structure:

├── FdF
│   ├── FdF
│   ├── Makefile
│   ├── Readme.md
│   ├── include
│   │   └── fdf.h
│   ├── libft
│   ├── mlx
│   ├── obj
│   │   ├── bounding_box.o
│   │   └── ...
│   ├── src
│   │   ├── bounding_box.c
│   │   └── ...
│   └── test_maps
│       ├── 10-2.fdf
│       └── ...

gcc -v:

Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Am I doing something dumb or am I unable to debug my programs this way?

CodePudding user response:

Apparently removing "miDebuggerPath": "${workspaceFolder}/FdF/FdF", Seemed to fix the issue.

  • Related