GCC dependency generation for a different output directory

后端 未结 7 432
深忆病人
深忆病人 2021-01-30 14:30

I\'m using GCC to generate a dependency file, but my build rules put the output into a subdirectory. Is there a way to tell GCC to put my subdirectory prefix in the dependency f

7条回答
  •  一生所求
    2021-01-30 15:14

    Ok, just to make sure I've got the question right: I'm assuming you have test.c which includes test.h, and you want to generate subdir/test.d (while not generating subdir/test.o) where subdir/test.d contains

    subdir/test.o: test.c test.h
    

    rather than

    test.o: test.c test.h
    

    which is what you get right now. Is that right?

    I was not able to come up with an easy way to do exactly what you're asking for. However, looking at Dependency Generation Improvements, if you want to create the .d file while you generate the .o file, you can use:

    gcc $(INCLUDES) -MMD $(CFLAGS) $(SRC) -o $(SUBDIR)/$(OBJ)
    

    (Given SRC=test.c, SUBDIR=subdir, and OBJ=test.o.) This will create both subdir/test.o and subdir/test.d, where subdir/test.d contains the desired output as above.

提交回复
热议问题