makefile for cppunit

时间:2013-04-13 15:54:39

标签: makefile cppunit

这是我的makefile:

#Makefile
CC=g++
CFLAGS=-lcppunit
OBJS=Money.o MoneyTest.o

all : $(OBJS)
    $(CC) $(OBJS) -o TestUnitaire

#création des objets 
Money.o: Money.cpp Money.hpp
    $(CC) -c Money.cpp $(CFLAGS)

MoneyTest.o: MoneyTest.cpp Money.hpp MoneyTest.hpp
    $(CC) -c MoneyTest.cpp $(CFLAGS)

clean:
    rm *.o $(EXEC)

当我运行这个makefile时,我会收到类似的错误:

  

g ++ Money.o MoneyTest.o -o TestUnitaire   Money.o:在函数main': Money.cpp:(.text+0x3c): undefined reference to CppUnit :: TestFactoryRegistry :: getRegistry(std :: basic_string,std :: allocator> const&)'   Money.cpp :(。text + 0x78):未定义引用CppUnit::TextTestRunner::TextTestRunner(CppUnit::Outputter*)' Money.cpp:(.text+0x8c): undefined reference to CppUnit :: TestRunner :: addTest(CppUnit :: Test *)'   Money.cpp :(。text + 0x98):未定义引用CppUnit::TextTestRunner::result() const' Money.cpp:(.text+0xec): undefined reference to CppUnit :: CompilerOutputter :: CompilerOutputter(CppUnit :: TestResultCollector *,std :: basic_ostream>&,std :: basic_string,std ::分配器> const&)'   Money.cpp :(。text + 0xfc):未定义引用CppUnit::TextTestRunner::setOutputter(CppUnit::Outputter*)' Money.cpp:(.text+0x168): undefined reference to CppUnit :: TextTestRunner :: run(std :: basic_string,std :: allocator>,bool,bool,bool)'   Money.cpp :(。text + 0x1a5):未定义引用CppUnit::TextTestRunner::~TextTestRunner()' Money.cpp:(.text+0x233): undefined reference to CppUnit :: TextTestRunner :: ~TextTestRunner()'

似乎我的班级之间没有联系。有什么问题?

1 个答案:

答案 0 :(得分:3)

-lcppunit中的CFLAGS标志不正确,这是您放置C编译器标志的位置。您是(a)编译C ++程序,而不是C程序,(b)-l标志是链接器标志,而不是编译器标志。此外,CC变量保存C编译器。您应该将CXX变量用于C ++编译器。您的makefile应该类似于:

#Makefile
CXX = g++
LDLIBS = -lcppunit
OBJS = Money.o MoneyTest.o

all : TestUnitaire

TestUnitaire: $(OBJS)
        $(CXX) $^ -o $@ $(LDFLAGS) $(LDLIBS)

#création des objets
%.o : %.cpp
        $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<

Money.o: Money.hpp
MoneyTest.o: Money.hpp MoneyTest.hpp

clean:
        rm *.o $(EXEC)