0

I'm trying to do some simple linked list practices to familiarize myself with C. I currently have the following makefile.

CC=gcc
CFLAGS=-Wall

app: linked_list.o app.c
    $(CC) $(CFLAGS) linked_list.o app.c -o app

node.o: node.h
    $(CC) $(CFLAGS) -c node.c

linked_list.o: linked_list.h
    $(CC) $(CFLAGS) -c linked_list.h -o app

When I run it I get this: gcc: error: linked_list.o: No such file or directory

I've tried reordering node.o and linked_list.o, but nothing worked.

Latcie
  • 701
  • 1
  • 7
  • 21

1 Answers1

3

You need to compile the .c file, not .h; and get rid of -o app.

linked_list.o: linked_list.c linked_list.h
    $(CC) $(CFLAGS) -c linked_list.c

Make sure to list both the .c and .h files as dependencies, both here and with node.o:

node.o: node.c node.h
    $(CC) $(CFLAGS) -c node.c
John Kugelman
  • 349,597
  • 67
  • 533
  • 578