相关疑难解决方法(0)

Makefile将目标文件从源文件的不同目录放入一个单独的目录中?

我正在使用UnitTest ++来允许我为某些C++代码(应该在Linux或Mac OS X上构建)创建单元测试.我有这样的目录结构:

src
- Foo.cpp
- Bar.cpp
test
- FooTest.cpp
- BarTest.cpp
- Main.cpp
- Makefile
UnitTest++
- libUnitTest++.a
Run Code Online (Sandbox Code Playgroud)

这个Makefile(改编自UnitTest ++ Makefile)可以很好地工作(使用GNU make):

test = TestFooAndBar

src = ../src/Foo.cpp \
    ../src/Bar.cpp

test_src = Main.cpp \
    FooTest.cpp \
    BarTest.cpp

lib = ../UnitTest++/libUnitTest++.a

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


.PHONY: all
all: $(test)
    @echo Running unit tests...
    @./$(test)

$(test): $(lib) $(test_objects) $(objects)
    @echo Linking $(test)...
    @$(CXX) $(LDFLAGS) -o $(test) $(test_objects) $(objects) $(lib)

.PHONY: clean
clean:
    -@$(RM) -f $(objects) …
Run Code Online (Sandbox Code Playgroud)

directory makefile object gnu-make

23
推荐指数
1
解决办法
5万
查看次数

标签 统计

directory ×1

gnu-make ×1

makefile ×1

object ×1