cpput的makefile

cpput的makefile,makefile,cppunit,Makefile,Cppunit,这是我的生成文件: #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

这是我的生成文件:

#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):对
CppUnit::TestFactoryRegistry::getRegistry的未定义引用(std::basic_string,std::allocator>const&)' Money.cpp:(.text+0x78):对
CppUnit::TextTestRunner::TextTestRunner(cppunt::outputer*)的未定义引用
Money.cpp:(.text+0x8c):对
CppUnit::TestRunner::addTest(CppUnit::Test*)的未定义引用 Money.cpp:(.text+0x98):对
CppUnit::TextTestRunner::result()const'的未定义引用
Money.cpp:(.text+0xec):对
CppUnit::CompilerOutputter::CompilerOutputter(CppUnit::TestResultCollector*,std::basic\u ostream>&,std::basic\u string,std::allocator>const&)的未定义引用 Money.cpp:(.text+0xfc):对
CppUnit::TextTestRunner::setoutputer(CppUnit::outputer*)的未定义引用
Money.cpp:(.text+0x168):对
CppUnit::TextTestRunner::run(std::basic_string,std::allocator>,bool,bool)的未定义引用 Money.cpp:(.text+0x1a5):对
CppUnit::TextTestRunner::~TextTestRunner()的未定义引用
Money.cpp:(.text+0x233):对
CppUnit::TextTestRunner::~TextTestRunner()的未定义引用


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

CFLAGS
中,
-lcppunit
标志不正确,这是放置C编译器标志的地方。您是编译C++程序而不是C程序,(b)<代码> -L/COD>标志是链接标志,不是编译器标志。另外,
CC
变量保存C编译器。对于C++编译器,应该使用<代码> CXX/COD>变量。您的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)
#生成文件
CXX=g++
LDLIBS=-lcppunit
OBJS=Money.o MoneyTest.o
全部:TestUnitaire
TestUnitaire:$(OBJS)
$(CXX)$^-o$@$(LDFLAGS)$(LDLIBS)
#飞机巡航
%.o:%.cpp
$(CXX)$(CPPFLAGS)$(CXXFLAGS)-o$@-c$<
Money.o:Money.hpp
MoneyTest.o:Money.hpp MoneyTest.hpp
清洁:
rm*.o$(执行)