Makefile error

compile all .c files in the directory into .o files.
execute makefile error: make: * No destination. Stop it.

C
Mar.04,2021

you don't need -o

if you just generate the target file.
*.o: *.c
    gcc -c $^

error in the above code

src=$(wildcard *.c)
obj=$(patsubst %.c,%.o,$(src))
$obj: $(src)
    gcc -c $(src)

then make


compile the c file in the directory to the corresponding object file

sources = $(wildcard *.c)
objects = $(patsubst %.c,%.o,$(sources))
$(objects) : %.o : %.c
    gcc -c $<
    
all: $(objects)

it is recommended that you take a look at makefile's static mode rules .

Menu