2012-04-19 19 views
5

Sanırım gerçekten aptalca bir şeyi özlüyorum.Cppunit'e nasıl bağlanırım?

Ben yüklü libcppunit var: (Ben Ubuntu 12.04 kullanıyorum)

$ 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 

Ve basit bir test var:

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

Ve bu derleyici çıktısı şöyledir:

$ 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 

Kitaplıkların/usr/lib

adresinde var olduğundan emin olmak için 210
$ ls /usr/lib/ | grep cppunit 
libcppunit-1.12.so.1 
libcppunit-1.12.so.1.0.0 
libcppunit.a 
libcppunit.la 
libcppunit.so 

Buna neden olan eksik şey nedir?

+0

buldum etrafında bir eser "-Wl - Gerektiğinde-no-" yerleştirmektir önce "-lcppunit" – Naddiseo

cevap

8

Sen

Bu yani derlemek için hangi dosyaların söylemek sonra bağlamak için kütüphaneler derleyici,

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

öyle Bunu da googletest için yapmak mümkün mü? –

+2

@MartinPfeffer, derleme seçeneklerinden sonra bağlantı seçeneklerini yerleştirmek için * genellikle * gereklidir. – steffen

1

I (Ubuntu 11.04 ile) aynı konuda koştu söylemek zorunda Ubuntu'da bir bug görünüyor. Çözümünüz "-Wl, - gerekmedikçe" benim için çalışıyor ve bağlantılı hata raporunda da bir geçici çözüm olarak bahsediliyor. Asıl sebebi keşfetmeye yetecek kadar dalmadım.

+0

https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition sayfasına bakın. Ne yazık ki bu yanlış bir yaklaşım gibi görünüyor. – moggi

1

sanırım kök nedenidir

MoneyApp_LDFLAGS = $(CPPUNIT_LIBS) -ldl 
yerine doğru

MoneyApp_LDADD = $(CPPUNIT_LIBS) -ldl 

ait

veya bir çizgi Makefile.am eklemek için teklif cppunit doc öğretici dosyası "money_example.html" daha doğru

CPPUNIT_LIBSgetiriyor
MoneyApp_LDADD = $(CPPUNIT_LIBS) 

beri Herhangi bir oranda. LDFLAGS, linker çalıştırılabilir adından hemen sonra bayrakları ekler, LDADD onları sonuna ekler, bu da orijinal gönderideki hatayı ortadan kaldırır. CppUnit ve dl (-lcppunit -ldl) kütüphanelerle