Search code examples
clinuxgccmakefilegdb

No debugging symbols found in ArchLinux with -g


I have a problem with GDB in Archlinux:

Even I add -g in my Makefile gdb say (no debugging symbols found)...done..

But if I compile manually gcc -g *.c it work...

I don't know what is don't work in my Makefile ?

My Archlinux:

Linux sime_arch 4.13.4-1-ARCH #1 SMP PREEMPT Thu Sep 28 08:39:52 CEST 2017 x86_64 GNU/Linux

My GCC:

gcc version 7.2.0 (GCC)

My Makefile:

SRC = test.c \
      test2.c

OBJ = $(SRC:.c=.o)

NAME    = test_name

CFLAG   = -Wall -Werror -Wextra

all:     $(NAME)

$(NAME): $(OBJ)
     gcc -g $(OBJ) -o $(NAME) $(CFLAG)

clean:  
    rm -f $(OBJ)

fclean: clean
    rm -f $(NAME)

re: fclean all}

Solution

  • You are adding the -g only to the linking command. The object files are generated by the auto compile target of make. This doesn't have the -g flag in it.

    You have 2 options -

    1. Change your variable CFLAG to CFLAGS and add -g to it. CFLAGS is picked by the auto compile command and it will create object files with debug info

    2. Add the following target -

      %.o: %.c gcc -g $(CFLAG) -o $@ $<

      before the $(NAME) target.

    The second one gives you more control with the targets but the first method is the standard way of compiling.

    Also, always try using standard names for variables unless you specifically need to name them separately.