पर क्लैंग के साथ लिंकिंग त्रुटि मैं CppUnit का उपयोग कर एक परीक्षण प्रोग्राम संकलित करने का प्रयास कर रहा हूं। समस्या यह नमूना कोड के साथ है:CppUnit मैक ओएस एक्स
//[...]
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;
}
मैं जोड़ने त्रुटि हो रही है:
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)
मैं -lcppunit ध्वज का उपयोग कर रहा है जब बजना लागू। जब मैं अपनी लिनक्स मशीन पर मेक फ़ाइल चलाता हूं, तो यह ठीक से संकलित करता है।
libcppunit-1.12.1.0.0.dylib
libcppunit-1.12.1.dylib
libcppunit.a
libcppunit.dylib
मेरे/usr/local/lib/में हैं। मैंने/usr/lib को इंस्टॉल करने का भी प्रयास किया और वही लिंकिंग त्रुटि होती है। किसी भी तरह की सहायता का स्वागत किया जाएगा।
बहुत बहुत धन्यवाद!
संपादित करें: मुझे समस्या का पता चला। मैं libC++ का उपयोग कर रहा हूं क्योंकि मैं अपने प्रोजेक्ट में std :: shared_ptr का उपयोग कर रहा हूं। समस्या यह है कि मैंने libC++ के साथ CppUnit संकलित करने का प्रयास किया लेकिन यह लिंकिंग त्रुटियों को फेंकता है। ऐसा लगता है कि इसे libstdC++ के साथ संकलित किया जाना चाहिए, जिसके लिए मुझे फ़िंक या मैकपोर्ट स्थापित करने की आवश्यकता होगी ताकि मैं gcc और libstdC++ का नवीनतम संस्करण इंस्टॉल कर सकूं। मैं वास्तव में इस से बचने की उम्मीद करता हूं क्योंकि इसे स्थापित करने की पूरी गड़बड़ी होगी। मैं भी share_ptr के लिए बूस्ट का उपयोग करने से बचने की उम्मीद करता हूं।
क्या इनमें से कोई भी संभव है? यदि नहीं, तो मैं शायद मैकपॉर्ट्स
जब आप अपनी समस्या हल करते हैं, तो अपना समाधान उत्तर के रूप में पोस्ट करें। –