2012-12-26 7 views
7

Próbuję skompilować program testowy za pomocą CppUnit. Problem polega na tym, ze ten przykładowy kod:CppUnit Błąd połączenia z językiem Clang w systemie Mac OS X

//[...] 

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; 
} 

Dostaję błąd łączący:

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) 

Używam flagę -lcppunit podczas wywoływania szczęk. Kiedy uruchamiam plik make na moim komputerze z systemem Linux, kompiluje on dobrze.

libcppunit-1.12.1.0.0.dylib 
libcppunit-1.12.1.dylib 
libcppunit.a 
libcppunit.dylib 

Są w moim/usr/local/lib /. Próbowałem nawet instalować do/usr/lib i pojawia się ten sam błąd łączenia. Każda pomoc będzie bardzo ceniona.

Dziękuję bardzo!

EDYCJA: Rozgryzłem problem. Używam libC++, ponieważ używam std :: shared_ptr w moim projekcie. Problem polega na tym, że próbowałem skompilować CppUnit z libC++, ale generuje błędy linkowania. Wygląda na to, że musi być skompilowany z libstdC++, który wymagałby zainstalowania Fink lub Macports, aby móc zainstalować najnowszą wersję gcc i libstdC++. Naprawdę mam nadzieję, że tego uniknę, ponieważ będzie cały bałagan próbujący go skonfigurować. Naprawdę mam również nadzieję uniknąć użycia Boost dla shared_ptr.

Czy to jest możliwe? Jeśli nie, prawdopodobnie poddam się i zainstaluję MacPorts

+0

Kiedy rozwiązujesz swój problem, umieść swoje rozwiązanie jako odpowiedź. –

Odpowiedz

1

Miałem ten sam problem. Po ustawieniu "Standardowej biblioteki C++" jako "libstdC++ (biblioteka standardowa GNU C++) jest OK".

Powiązane problemy