Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile Error - No Such File or Directory

Tags:

makefile

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
like image 223
AndroidDev Avatar asked Nov 18 '25 20:11

AndroidDev


1 Answers

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.

like image 164
Beta Avatar answered Nov 21 '25 10:11

Beta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!