GNU Make pattern to build output in different directory than src

此生再无相见时 提交于 2019-11-27 20:04:33

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.

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.

Alexey Semenyuk

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!