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

后端 未结 1 1247
暗喜
暗喜 2020-12-02 19:15

I\'m using UnitTest++ to allow me to create unit tests for some C++ code (that should build on Linux or Mac OS X). I have a directory structure like this:

s         


        
相关标签:
1条回答
  • 2020-12-02 19:47

    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 $@
    
    0 讨论(0)
提交回复
热议问题