Frage Problem mit der Ausführung der Boost-Bibliothek


Ich bin Anfänger zu Ubuntu und Boost. Ich habe ubuntu 11.10 installiert und befolgte die Anweisungen von der Website (http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/), um BOOST Unit-Test zu versuchen. Ich installiere die Boost-Bibliothek und kopiere den Code wie in Teil 3 und versuche es auszuführen, aber ich habe Fehler während der Ausführung.

8w6Wa.o: In function `init_unit_test()':
bTest.cpp:(.text+0x51): undefined reference to
`boost::unit_test::framework::master_test_suite()'
/tmp/ccZ8w6Wa.o: In function `main':
bTest.cpp:(.text+0x9f): undefined reference to
`boost::unit_test::unit_test_main(bool (*)(), int, char**)'
/tmp/ccZ8w6Wa.o: In function `universeInOrder::test_method()':
bTest.cpp:(.text+0x121): undefined reference to
`boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char
const>, unsigned int, boost::unit_test::basic_cstring<char const>)'
bTest.cpp:(.text+0x1e3): undefined reference to
`boost::test_tools::tt_detail::check_impl(boost::test_tools::predicate_result
const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char
const>, unsigned int, boost::test_tools::tt_detail::tool_level,
boost::test_tools::tt_detail::check_type, unsigned int, ...)'
/tmp/ccZ8w6Wa.o: In function `__static_initialization_and_destruction_0(int, int)':
bTest.cpp:(.text+0x2ea): undefined reference to
`boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*,
unsigned long)'
/tmp/ccZ8w6Wa.o: In function `boost::unit_test::unit_test_log_t::unit_test_log_t()':
bTest.cpp:(.text._ZN5boost9unit_test15unit_test_log_tC2Ev[_ZN5boost9unit_test15unit_test_log_tC5Ev]+0x21):
undefined reference to `vtable for boost::unit_test::unit_test_log_t'
/tmp/ccZ8w6Wa.o: In function
`boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused>
c    onst&, boost::unit_test::basic_cstring<char const>)':
bTest.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused>
const&, boost::unit_test::basic_cstring<char const>)]+0x1d): undefined reference to
`boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char
const>)'
bTest.cpp:(.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[boost::unit_test::make_test_case(boost::unit_test::callback0<boost::unit_test::ut_detail::unused>
const&, boost::unit_test::basic_cstring<char const>)]+0x5d): undefined reference to
`boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>,
boost::unit_test::callback0<boost::unit_test::ut_detail::unused> const&)'
/tmp/ccZ8w6Wa.o: In function `boost::unit_test::unit_test_log_t::~unit_test_log_t()':
bTest.cpp:(.text._ZN5boost9unit_test15unit_test_log_tD2Ev[_ZN5boost9unit_test15unit_test_log_tD5Ev]+0xb):
undefined reference to `vtable for boost::unit_test::unit_test_log_t'
collect2: ld returned 1 exit status

Ich versuche auch, sudo apt-get install libboost-dev-all immer noch denselben Fehler zu installieren.

Bitte helfen Sie mir, dieses Problem zu lösen. Danke im Voraus.


4
2018-02-15 02:51


Ursprung




Antworten:


Ich habe die Lösung die Reihenfolge des Befehls statt zu verwenden

g++ -o hello -lboost_unit_test_framework hello.cpp (was früher in der früheren Version funktioniert hat)

ändere es zu

g++ -o hello hello.cpp -lboost_unit_test_framework

Das funktioniert gut.

Ich habe darauf hingewiesen https://stackoverflow.com/questions/7755668/linking-against-boost-thread-fails-under-ubuntu-11-10


4
2018-02-22 02:23