如果我的make文件中有这样的规则:

CC = g++
CFLAGS = -Wall
COMPILE = $(CC) $(CFLAGS) -c

src = A.cpp \
      main.cpp

test_src = Test.cpp
test = testAll

OBJFILES := $(patsubst %.cpp,%.o,$(src))
TEST_OBJS := $(patsubst %.cpp,%.o,$(test_src))

%.o: %.cpp
    $(COMPILE) -I UnitTest++/src -LUnitTest++/ -l UnitTest++ -o $@ $<

我最终将UnitTest ++包含并链接到非测试文件,例如main和A.cpp
如何仅使Test类与测试库链接?

最佳答案

指定您的规则适用于哪些文件:

$(TEST_OBJS): %.o: %.cpp
    $(COMPILE) -I UnitTest++/src -LUnitTest++/ -l UnitTest++ -o $@ $<

07-24 09:44
查看更多