简体   繁体   中英

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}

Thanks in advance

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.

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