首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于cppunit的makefile

用于cppunit的makefile
EN

Stack Overflow用户
提问于 2013-04-13 15:54:38
回答 1查看 2.5K关注 0票数 1

这是我的makefile

代码语言:javascript
复制
#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时,会得到这样的错误:

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

似乎我们班之间没有任何联系。有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-13 16:10:42

-lcppunit标志在CFLAGS中是不正确的,这是放置C编译器标志的地方。您是(a)编译C++程序,而不是C程序,和(b) -l标志是链接器标志,而不是编译器标志。此外,CC变量包含C编译器。您应该将CXX变量用于C++编译器。生成文件应该如下所示:

代码语言:javascript
复制
#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)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15989714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档