Stasv
Stasv

Reputation: 115

makefile not finding the .o file

I have the strangest problem. when I run : make tests in the console I get the following error: gcc: album_test.o: No such file or directory

makefile

sorry for attaching the content as a pic, the site kept giving me a: "Your post appears to contain code that's not properly formatted as code"

when I change this line :

album_test.o: ./tests/album_test.c album.h

to be :

album_test.o: album_test.c album.h

and place the album_test.c in the same directory as the makefile everything compiles!

It's very important that the file will be in a separate tests directory. any ideas?

Thanks!

Upvotes: 0

Views: 1725

Answers (1)

Carl Norum
Carl Norum

Reputation: 224844

You're trying to use make's built-in implicit rules to build your object files. That works when make can find the source file in the current directory, but not otherwise. Update this rule:

album_test.o: ./tests/album_test.c album.h

To include a recipe:

album_test.o: ./tests/album_test.c album.h
    $(CC) $(CFLAGS) -c -o $@ $<

Upvotes: 4

Related Questions