Makefile - move object files

前端 未结 2 537
清酒与你
清酒与你 2021-01-06 14:45

After a bit of searching, I\'ve managed to throw together the following Makefile:

CC = gcc
CFLAGS = -c -Wall
LDFLAGS = 
SOURCEFILES = main.c
SOURCES = src/$(         


        
2条回答
  •  被撕碎了的回忆
    2021-01-06 15:29

    Something like this?

    SOURCES = src/main.c
    OBJECTS = obj/main.o
    
    ...
    
    obj/%.o: src/%.c
        $(CC) $(CFLAGS) $< -o $@
    

    Once that's working, you can add further tricks, like this:

    OBJECTS = $(patsubst src/%.c, obj/%.o, $(SOURCES)
    

提交回复
热议问题