2012-12-26 8 views
7

CppUnit을 사용하여 테스트 프로그램을 컴파일하려고합니다. 문제는이 샘플 코드이다 : 나는 연결 오류가 발생하고CppUnit Mac OS X에서 Clang과 연결 오류가 발생했습니다.

//[...] 

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

: 그 소리를 호출 할 때 나는 -lcppunit 플래그를 사용하고

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) 

. Linux 컴퓨터에서 make 파일을 실행할 때 컴파일이 잘됩니다.

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

내/usr/local/lib /에 있습니다. 나는/usr/lib에 설치를 시도해 보았지만 동일한 연결 오류가 발생합니다. 어떤 도움이라도 대단히 감사하겠습니다.

대단히 감사합니다.

편집 : 문제를 파악했습니다. 내 프로젝트에서 std :: shared_ptr을 사용하고 있기 때문에 libC++을 사용하고 있습니다. 문제는 libC++로 CppUnit 컴파일을 시도했지만 링크 오류가 발생한다는 것입니다. 그것은 gcc와 libstdC++의 최신 버전을 설치할 수 있도록 Fink 나 Macports를 설치해야하는 libstdC++로 컴파일해야합니다. 나는 이것을 망칠 수 있기를 정말로 바라고 있기 때문에 이것을 피하기를 정말로 바란다. shared_ptr에 Boost를 사용하지 않기를 바란다.

이 중 하나가 가능합니까? 그렇지 않다면 아마도 MacPorts를 포기하고 설치할 것입니다.

+0

문제를 해결할 때 솔루션을 답으로 게시하십시오. –

답변

1

같은 문제가있었습니다. "C++ 표준 라이브러리"를 "libstdC++ (GNU C++ 표준 라이브러리)"로 설정 한 후에는 정상입니다.