Reputation: 9161
If I have a rule like this in my make file:
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 $@ $<
I end up including and linking UnitTest++ to non test files such as main and A.cpp How can I make only make Test classes link with the test libraries?
Upvotes: 1
Views: 161
Reputation: 279245
Specify which files your rule applies to:
$(TEST_OBJS): %.o: %.cpp
$(COMPILE) -I UnitTest++/src -LUnitTest++/ -l UnitTest++ -o $@ $<
Upvotes: 3