AndroidDev
AndroidDev

Reputation: 21237

Makefile Error - No Such File or Directory

I'm trying to integrate a new file into my program compilation. I'm thoroughly confused about the "routed.o:" line. My program has one main file called "routed" and two support files that contain functions that are called by the main file. Can anyone help me understand how to compile this into a single program? Thank you!

EDIT: I figured this out. For the sake of posterity, I've commented out my "stupid" lines and replace them with something that works.

CC = gcc
CFLAGS = -c -g -Wall -Wextra
DEPS = routed.h

all: routed_LS

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

helper_funcs.o: helper_funcs.c
    $(CC) -c helper_funcs.c -o helper_funcs.o

dijkstra.o: dijkstra.c
    $(CC) -c dijkstra.c -o dijkstra.o

# routed.o: routed.c helper_funcs.o dijkstra.o
#   $(CC) -c routed.c -o routed.o -o dijkstra.o

routed.o: routed.c
$(CC) -c routed.c

# routed: routed.o helper_funcs.o dijkstra.o
#   $(CC) -o routed routed.o helper_funcs.o dijkstra.o 

routed: routed.o dijkstra.o helper_funcs.o
$(CC) -o routed routed.o dijkstra.o helper_funcs.o  

clean:
    rm -f *.o
    rm -f routed

Here is the terminal output:

rm -f *.o
rm -f routed
gcc -c helper_funcs.c -o helper_funcs.o
gcc -c dijkstra.c -o dijkstra.o
gcc -c routed.c -o routed.o -o dijkstra.o
gcc -o routed routed.o helper_funcs.o dijkstra.o 
i686-apple-darwin11-llvm-gcc-4.2: routed.o: No such file or directory
make: *** [routed] Error 1

Upvotes: 3

Views: 5602

Answers (2)

AndroidDev
AndroidDev

Reputation: 21237

I really didn't understand what I was doing, as you can clearly tell. The way that I fixed this was with the following changes:

# routed.o: routed.c helper_funcs.o dijkstra.o
#   $(CC) -c routed.c -o routed.o -o dijkstra.o

routed.o: routed.c
$(CC) -c routed.c

# routed: routed.o helper_funcs.o dijkstra.o
#   $(CC) -o routed routed.o helper_funcs.o dijkstra.o 

Upvotes: 0

Beta
Beta

Reputation: 99084

This command:

$(CC) -c routed.c -o routed.o -o dijkstra.o

doesn't do what you think it does. I'm not entirely certain what you were attempting here, but the compiler sets the name of the output file to "routed.o", and then dutifully sets it to "dijkstra.o". The command produces an object file called "dijkstra.o", and that's all. The routed.o rule doesn't actually produce a file called routed.o, and when the linker reaches for that object file, it can't find it.

Upvotes: 3

Related Questions