Answer the question
In order to leave comments, you need to log in
How to build an executable file from 2 sources using make?
In general, two files with the source code main_0.c main_1.c and the third header file header.h in which all the prototypes and global variables.
Here is the text of the makefile:
/home/tr/tr: /home/tr/main_0.o /home/tr/main_1.o
cc -o /home/tr/main_0.o /home/tr/main_1.o
/home/tr/main_0.o: /home/tr/main_0.c /home/tr/header.h
cc -c /home/tr/main_0.c
/home/tr/main_1.o: /home/tr/main_1.c /home/tr/header.h
cc -c /home/tr/main_1.c
Answer the question
In order to leave comments, you need to log in
As you have already been answered in a comment, you simply didn't provide an option for -o.
In general, you should never use absolute paths in a Makefile.
And yet, if you change your header.h, then make will not know about it.
Compilers have special options to generate .c file dependencies from headers.
Here is a generic Makefile for simple projects:
PROJECT = tr
SOURCES = main_0.c main_1.c
OBJECTS = $(SOURCES:.c=.o)
HEADER_DEPS = $(SOURCES:.c=.d)
.PHONY: all
all: $(PROJECT)
$(PROJECT): $(OBJECTS)
$(CC) $(CFLAGS) $^ -o [email protected]
-include $(HEADER_DEPS)
%.o: %.c
$(CC) $(CFLAGS) -MM -MT [email protected] -MF $(patsubst %.o,%.d,[email protected]) $<
$(CC) $(CFLAGS) -c $< -o [email protected]
.PHONY: clean
clean:
$(RM) $(PROJECT) $(OBJECTS) $(HEADER_DEPS)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question