Makefile to put object files from source files different directories into a single, separate directory?

限于喜欢 提交于 2019-11-27 12:06:38
Beta

There's more than one way to do it, but this is a pretty good one (I really should have that hotkeyed).

vpath %.cpp ../src

src = Foo.cpp Bar.cpp 
test_src = Main.cpp FooTest.cpp BarTest.cpp 

objects = $(patsubst %.cpp,obj/%.o,$(src)) 
test_objects = $(patsubst %.cpp,obj/%.o,$(test_src)) 

$(objects): | obj

obj:
  @mkdir -p $@

obj/%.o : %.cpp
  @echo $< 
  @$(CXX) $(CXXFLAGS) -c $< -o $@
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!