当使用Netbean搭配C++插件开发时,如果使用CppUnit进行测试,每添加一个测试有一定概率会破坏Makefile文件,导致找不到CppUnit:
?
/home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.cpp:38: undefined reference to `CppUnit::SourceLine::SourceLine(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.cpp:38: undefined reference to `CppUnit::SourceLine::~SourceLine()' /home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.cpp:38: undefined reference to `CppUnit::SourceLine::~SourceLine()' build/Debug/GNU-Linux-x86/tests/tests/SortClass.o: In function `SortClass::getTestNamer__()': /home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.h:14: undefined reference to `CppUnit::TestNamer::TestNamer(std::type_info const&)' /home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.h:14: undefined reference to `CppUnit::TestNamer::~TestNamer()' build/Debug/GNU-Linux-x86/tests/tests/SortClass.o: In function `~TestSuiteBuilderContext': /usr/include/cppunit/extensions/TestSuiteBuilderContext.h:101: undefined reference to `CppUnit::TestSuiteBuilderContextBase::~TestSuiteBuilderContextBase()' /usr/include/cppunit/extensions/TestSuiteBuilderContext.h:101: undefined reference to `CppUnit::TestSuiteBuilderContextBase::~TestSuiteBuilderContextBase()' build/Debug/GNU-Linux-x86/tests/tests/SortClass.o: In function `SortClass::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&)': /home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.h:16: undefined reference to `CppUnit::TestSuiteBuilderContextBase::getTestNameFor(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const' /home/programmer/workspace/InterviewTest/CppInterview/tests/SortClass.h:16: undefined reference to `CppUnit::TestSuiteBuilderContextBase::addTest(CppUnit::Test*)' build/Debug/GNU-Linux-x86/tests/tests/SortClass.o: In function `SortClass::suite()':
?
?
这是Netbean的issue,它会自动把一些运行测试时的-lcppunit参数删除了。
?
解决方法:
?
打开nbproject/Makefile-Debug.mk,在.build-tests-conf: .build-conf ${TESTFILES}以下的每个${LDLIBSOPTIONS}后面加上 -lcppunit 参数
?
?
------------------------------------------------
.build-tests-conf: .build-conf ${TESTFILES}
${TESTDIR}/TestFiles/f1: ${TESTDIR}/tests/SortClass.o ${TESTDIR}/tests/testrunnerone.o ${OBJECTFILES:%.o=%_nomain.o}
${MKDIR} -p ${TESTDIR}/TestFiles
${LINK.cc} -o ${TESTDIR}/TestFiles/f1 $^ ${LDLIBSOPTIONS} -lcppunit
?
?
每添加一个测试有一定概率会自动删除-lcppunit参数,所以需要手动加上去,等后续的netbean C++插件解决吧。
?
?
?
?
?