2012-04-19 9 views
5

मुझे लगता है कि मैं यहाँ वास्तव में बेवकूफ कुछ याद कर रहा हूँ।मैं cppunit से कैसे लिंक करूं?

मैं libcppunit है स्थापित: (मैं Ubuntu 12.04 उपयोग कर रहा हूँ)

$ apt-cache policy libcppunit-dev 
libcppunit-dev: 
    Installed: 1.12.1-4 
    Candidate: 1.12.1-4 
    Version table: 
*** 1.12.1-4 0 
     500 http://archive.ubuntu.com/ubuntu/ precise/main amd64 Packages 
     100 /var/lib/dpkg/status 

$ apt-cache policy libcppunit-1.12-1 
libcppunit-1.12-1: 
    Installed: 1.12.1-4 
    Candidate: 1.12.1-4 
    Version table: 
*** 1.12.1-4 0 
     500 http://archive.ubuntu.com/ubuntu/ precise/main amd64 Packages 
     100 /var/lib/dpkg/status 

और मैं एक साधारण परीक्षण है:

#include <iostream> 

#include <cppunit/ui/text/TestRunner.h> 
#include <cppunit/CompilerOutputter.h> 
#include <cppunit/TestFixture.h> 
#include <cppunit/extensions/HelperMacros.h> 

int main() { 
    CppUnit::Test* suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); 

    CppUnit::TextUi::TestRunner runner; 
    runner.addTest(suite); 
    runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr)); 

    return runner.run() ? 0 : 1; 
} 

और मैं इस संकलक उत्पादन होता है:

$ g++ -lcppunit -o test.bin test.cpp 
/tmp/ccoQDuGC.o: In function `main': 
test.cpp:(.text+0x36): undefined reference to `CppUnit::TestFactoryRegistry::getRegistry(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
test.cpp:(.text+0x75): undefined reference to `CppUnit::TextTestRunner::TextTestRunner(CppUnit::Outputter*)' 
test.cpp:(.text+0x8b): undefined reference to `CppUnit::TestRunner::addTest(CppUnit::Test*)' 
test.cpp:(.text+0x9a): undefined reference to `CppUnit::TextTestRunner::result() const' 
test.cpp:(.text+0xe2): undefined reference to `CppUnit::CompilerOutputter::CompilerOutputter(CppUnit::TestResultCollector*, std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
test.cpp:(.text+0xf4): undefined reference to `CppUnit::TextTestRunner::setOutputter(CppUnit::Outputter*)' 
test.cpp:(.text+0x150): undefined reference to `CppUnit::TextTestRunner::run(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, bool, bool)' 
test.cpp:(.text+0x189): undefined reference to `CppUnit::TextTestRunner::~TextTestRunner()' 
test.cpp:(.text+0x227): undefined reference to `CppUnit::TextTestRunner::~TextTestRunner()' 
collect2: ld returned 1 exit status 

यह सुनिश्चित करने के लिए, पुस्तकालय/usr/lib

के अंतर्गत मौजूद हैं 210
$ ls /usr/lib/ | grep cppunit 
libcppunit-1.12.so.1 
libcppunit-1.12.so.1.0.0 
libcppunit.a 
libcppunit.la 
libcppunit.so 

मुझे क्या याद आ रही है जो इसका कारण बन रही है?

+0

आसपास मैंने पाया एक काम ", -Wl - कोई के रूप में की जरूरत" जगह से पहले "-lcppunit" – Naddiseo

उत्तर

8

आप संकलक जो के बाद से जोड़ने के लिए आप इसे बताओ जो संकलित करने के लिए फ़ाइलों को पुस्तकालयों, यानी

g++ test.cpp -lcppunit -o test.bin 
+0

यह है googletest के लिए भी ऐसा करना संभव है? –

+2

@ मार्टिनफेफर यह * आमतौर पर * संकलन विकल्पों के बाद लिंक विकल्प रखने के लिए आवश्यक है। – steffen

1

मैं (उबंटू 11.04 के साथ) एक ही मुद्दा में भाग

यह बताने के लिए है उबंटू में bug प्रतीत होता है। आपका कामकाज "-ब्लूएल, - बिना किसी आवश्यक" मेरे लिए काम करता है और लिंक की गई बग रिपोर्ट में वर्कअराउंड के रूप में भी इसका उल्लेख किया जाता है। मैंने वास्तविक कारण खोजने के लिए पर्याप्त रूप से इसमें डुबकी नहीं डाली है।

+0

https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition देखें। अफसोस की बात यह गलत दृष्टिकोण प्रतीत होता है। – moggi

1

मूल कारण मुझे लगता है कि है CppUnit डॉक ट्यूटोरियल फ़ाइल "money_example.html" एक पंक्ति

MoneyApp_LDFLAGS = $(CPPUNIT_LIBS) -ldl 
सही

MoneyApp_LDADD = $(CPPUNIT_LIBS) -ldl 

के बजाय

या Makefile.am में जोड़ने का प्रस्ताव है जो और भी अधिक सही

MoneyApp_LDADD = $(CPPUNIT_LIBS) 

के बाद से CPPUNIT_LIBSमें लाता है किसी भी दर पर। LDFLAGS लिंकर निष्पादन योग्य नाम के ठीक बाद झंडे जोड़ता है, LDADD उन्हें मूल पोस्ट में त्रुटि को समाप्त करने के अंत में जोड़ता है। CppUnit और डीएल (-lcppunit -ldl) पुस्तकालयों के साथ

संबंधित मुद्दे