Proper method for wildcard targets in GNU Make

前端 未结 1 1237
迷失自我
迷失自我 2021-02-12 12:51

I am trying to write a Makefile with my source and object files separated and I can\'t seem to figure out the proper way to accomplish this. I have two methods that work but I\'

1条回答
  •  野性不改
    2021-02-12 13:30

    Your first example is almost there:

    SRC = $(wildcard src/*.cpp)
    OBJ = $(patsubst src/%.cpp, obj/%.o, $(SRC))
    
    prog: $(OBJ)
      $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) $(OBJ) -o prog 
    
    obj/%.o: src/%.cpp
      $(CC) $(CFLAGS) -c $< -o $@
    

    0 讨论(0)
提交回复
热议问题