C++ Mac OS X上的CPPFUnit链接错误与叮当声
我正在尝试使用CppUnit编译一个测试程序。问题是,使用此示例代码:C++ Mac OS X上的CPPFUnit链接错误与叮当声,c++,macos,linker,clang,cppunit,C++,Macos,Linker,Clang,Cppunit,我正在尝试使用CppUnit编译一个测试程序。问题是,使用此示例代码: //[...] class EntityComponentTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( EntityComponentTest ); CPPUNIT_TEST( testGetComponents ); CPPUNIT_TEST_SUITE_END(); Entity e; public: void setUp(){ e.add
//[...]
class EntityComponentTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( EntityComponentTest );
CPPUNIT_TEST( testGetComponents );
CPPUNIT_TEST_SUITE_END();
Entity e;
public:
void setUp(){
e.addComponent("1", new TestComponent("Hello 1"));
e.addComponent("2", new TestComponent("Hello 2"));
}
void tearDown(){}
void testGetComponents()
{
TestComponent &first = static_cast<TestComponent&>(e.getComponent("1"));
TestComponent &second = static_cast<TestComponent&>(e.getComponent("2"));
CPPUNIT_ASSERT(first.msg == "Hello 1");
CPPUNIT_ASSERT(second.msg == "Hello 2");
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( EntityComponentTest );
int main(void)
{
//followed from tutorial
CppUnit::TextUi::TestRunner run;
CppUnit::TestFactoryRegistry &r = CppUnit::TestFactoryRegistry::getRegistry();
run.addTest(r.makeTest());
run.run("", false, true);
return 0;
}
在my/usr/local/lib/中。我甚至试着安装到/usr/lib,同样的链接错误也发生了。任何帮助都将不胜感激
非常感谢
编辑:我解决了这个问题。我使用libc++是因为我在项目中使用std::shared_ptr。问题是我尝试用libc++编译CppUnit,但它会引发链接错误。它似乎必须用libstdc++编译,这需要我安装Fink或Macports,以便安装最新版本的gcc和libstdc++。我真的希望避免这种情况,因为在设置时会出现一大堆混乱。我真的希望避免使用Boost来实现共享的ptr
这有可能吗?如果没有,我可能会放弃并安装MacPorts,我也有同样的问题。设置“C++标准库”为“LISTSTDC++ +(GNU C++标准库)”,可以解决问题。< /P>当您解决自己的问题时,将您的解决方案作为答案发布。
Undefined symbols for architecture x86_64:
"CppUnit::SourceLine::SourceLine(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
EntityComponentTest::testGetComponents() in EntityComponentTest.cpp.o
"CppUnit::TextTestRunner::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, bool, bool)", referenced from:
_main in EntityComponentTest.cpp.o
"CppUnit::TestFactoryRegistry::getRegistry(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in EntityComponentTest.cpp.o
CppUnit::AutoRegisterSuite<EntityComponentTest>::AutoRegisterSuite() in EntityComponentTest.cpp.o
"CppUnit::Message::Message(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
EntityComponentTest::testGetComponents() in EntityComponentTest.cpp.o
"CppUnit::TestCase::TestCase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
CppUnit::TestCaller<EntityComponentTest>::TestCaller(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void (EntityComponentTest::*)(), EntityComponentTest*) in EntityComponentTest.cpp.o
"CppUnit::TestSuite::TestSuite(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
EntityComponentTest::suite() in EntityComponentTest.cpp.o
"CppUnit::TestSuiteBuilderContextBase::getTestNameFor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
EntityComponentTest::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&) in EntityComponentTest.cpp.o
"CppUnit::Test::findTestPath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, CppUnit::TestPath&) const", referenced from:
vtable for CppUnit::TestCaller<EntityComponentTest> in EntityComponentTest.cpp.o
"CppUnit::Test::resolveTestPath(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for CppUnit::TestCaller<EntityComponentTest> in EntityComponentTest.cpp.o
"CppUnit::Test::findTest(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
vtable for CppUnit::TestCaller<EntityComponentTest> in EntityComponentTest.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
libcppunit-1.12.1.0.0.dylib
libcppunit-1.12.1.dylib
libcppunit.a
libcppunit.dylib