GNU Make pattern to build output in different directory than src

后端 未结 3 393
孤城傲影
孤城傲影 2020-12-05 10:00

I\'m trying to create a Makefile which places my .o files in a different directory than my source files. I\'m trying to use a pattern rule so I don\'t have to c

相关标签:
3条回答
  • 2020-12-05 10:45

    Instead of building objects in another directory, you could try building objects from sources in another directory: put your makefile in the directory where the objects are going to be and tell make to look for sources elsewhere using VPATH. This works best if all object files are supposed to end up in the same directory.

    0 讨论(0)
  • 2020-12-05 10:48

    After re-reading the documentation on static pattern rules, I derived the following pattern rule which seems to work.

    $(OBJ_DEBUG): $(OBJDIR_DEBUG)/%.o: %.cpp
        $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c $< -o $@
    

    I'm not sure this is the best approach, and I'm open to suggestions.

    0 讨论(0)
  • 2020-12-05 10:51

    Makefile that "duplicates" source tree in separate build directory by running GCC on each source - https://stackoverflow.com/a/41924169/4224163

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