boost unit test compilation problem

Hi list. I'm trying to compile and run simple unit test, but only to fail: #include <boost/test/unit_test.hpp> using namespace std; using namespace boost::unit_test; using namespace boost; void force_division_by_zero() { BOOST_CHECKPOINT("About to force division by zero!"); int i = 1, j = 0; i = i / j; } test_suite* init_unit_test_suite(int, char*) { test_suite* test = BOOST_TEST_SUITE("Unit test example2"); test->add(BOOST_TEST_CASE(&force_division_by_zero), 1); return test; } This does not compile though this is the program shown in the document. The errors are: /usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../lib64/crt1.o (.text+0x20): In function `_start': : undefined reference to `main' /tmp/ccytTZBu.o(.text+0x8f): In function `force_division_by_zero()': backoff_ngram_lm_test.cpp: undefined reference to `boost::test_tools::tt_detail::check_impl(boost::test_tools:: predicate_result const&, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)' /tmp/ccytTZBu.o(.text+0x173): In function `init_unit_test_suite(int, char*)': backoff_ngram_lm_test.cpp: undefined reference to `boost::unit_test::test_suite::test_suite(boost::unit_test:: basic_cstring<char const>)' /tmp/ccytTZBu.o(.text+0x1e8):backoff_ngram_lm_test.cpp: undefined reference to `boost::unit_test::test_suite::add(boost::unit_test::test_unit*, unsigned long, unsigned int)' /tmp/ccytTZBu.o(.gnu.linkonce.t._ZN5boost9unit_test14make_test_case ERKNS0_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>)]+0x35): In function `boost::unit_test::make_test_case(boost::unit_test::callback0 <boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>)': backoff_ngram_lm_test.cpp: undefined reference to `boost::unit_test::ut_detail::normalize_test_case_name(boost:: unit_test::basic_cstring<char const>)' /tmp/ccytTZBu.o(.gnu.linkonce.t._ZN5boost9unit_test14make_test_ caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstring IKcEE[boost::unit_test::make_test_case(boost::unit_test::callback0 <boost::unit_test::ut_detail::unused> const&, boost::unit_test::basic_cstring<char const>)]+0x65):backoff_ngram_lm_test.cpp: 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&)' collect2: ld returned 1 exit status I'm compiling the sorce like g++ filename.cpp. My environments: $ g++ -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=x86_64- redhat-linux Thread model: posix gcc version 4.0.2 20051125 (Red Hat 4.0.2-8) Any idea? Sincerely, Minkoo Seo

"Minkoo Seo" <minkoo.seo@gmail.com> wrote in message news:loom.20060801T091530-365@post.gmane.org...
Hi list.
This does not compile though this is the program shown in the document. The errors are:
/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../lib64/crt1.o (.text+0x20): In function `_start': : undefined reference to `main' /tmp/ccytTZBu.o(.text+0x8f): In function `force_division_by_zero()': backoff_ngram_lm_test.cpp: undefined reference to `boost::test_tools::tt_detail::check_impl(boost::test_tools:: predicate_result const&, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)' /tmp/ccytTZBu.o(.text+0x173): In function `init_unit_test_suite(int, char*)':
You need to link with the pre-built standalone library. Use either Jam with Boost.Build system to build the library or you could use your own make system. But in that case you will need to come up with makefile yourself. The framework doesn't need much special compilation flags. Consult docs and Jam for more details. Gennadiy

# gennadiy.rozental@thomson.com / 2006-08-01 10:44:48 -0400:
"Minkoo Seo" <minkoo.seo@gmail.com> wrote in message news:loom.20060801T091530-365@post.gmane.org...
Hi list.
This does not compile though this is the program shown in the document. The errors are:
/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../lib64/crt1.o (.text+0x20): In function `_start': : undefined reference to `main' /tmp/ccytTZBu.o(.text+0x8f): In function `force_division_by_zero()': backoff_ngram_lm_test.cpp: undefined reference to `boost::test_tools::tt_detail::check_impl(boost::test_tools:: predicate_result const&, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)' /tmp/ccytTZBu.o(.text+0x173): In function `init_unit_test_suite(int, char*)':
You need to link with the pre-built standalone library. Use either Jam with Boost.Build system to build the library or you could use your own make system. But in that case you will need to come up with makefile yourself. The framework doesn't need much special compilation flags. Consult docs and Jam for more details.
Yeah, the docs are quite explicit about the need to link with the libs. Your Makefile could be as simple as: CXXFLAGS= -I/usr/local/include LDFLAGS= -L/usr/local/lib -lboost_filesystem -lboost_program_options fubar: fubar.cpp $(CXX) $(CXXFLAGS) $(LDFLAGS) -o fubar fubar.cpp -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991

"Roman Neuhauser" <neuhauser@sigpipe.cz> wrote in message news:20060801165504.GB8222@dagan.sigpipe.cz...
# gennadiy.rozental@thomson.com / 2006-08-01 10:44:48 -0400:
"Minkoo Seo" <minkoo.seo@gmail.com> wrote in message news:loom.20060801T091530-365@post.gmane.org...
Hi list.
This does not compile though this is the program shown in the document. The errors are:
/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../lib64/crt1.o (.text+0x20): In function `_start': : undefined reference to `main' /tmp/ccytTZBu.o(.text+0x8f): In function `force_division_by_zero()': backoff_ngram_lm_test.cpp: undefined reference to `boost::test_tools::tt_detail::check_impl(boost::test_tools:: predicate_result const&, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)' /tmp/ccytTZBu.o(.text+0x173): In function `init_unit_test_suite(int, char*)':
You need to link with the pre-built standalone library. Use either Jam with Boost.Build system to build the library or you could use your own make system. But in that case you will need to come up with makefile yourself. The framework doesn't need much special compilation flags. Consult docs and Jam for more details.
Yeah, the docs are quite explicit about the need to link with the libs. Your Makefile could be as simple as:
CXXFLAGS= -I/usr/local/include LDFLAGS= -L/usr/local/lib -lboost_filesystem -lboost_program_options
These does not look right . I don;t think you need program options or filesystem to build a unbit test framework *library* ;) Gennadiy

The unit test library uses program-options and filesystem... Therefore you do. On 8/1/06, Gennadiy Rozental <gennadiy.rozental@thomson.com> wrote:
"Roman Neuhauser" <neuhauser@sigpipe.cz> wrote in message news:20060801165504.GB8222@dagan.sigpipe.cz...
# gennadiy.rozental@thomson.com / 2006-08-01 10:44:48 -0400:
"Minkoo Seo" <minkoo.seo@gmail.com> wrote in message news:loom.20060801T091530-365@post.gmane.org...
Hi list.
This does not compile though this is the program shown in the document. The errors are:
/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../lib64/crt1.o (.text+0x20): In function `_start': : undefined reference to `main' /tmp/ccytTZBu.o(.text+0x8f): In function `force_division_by_zero()': backoff_ngram_lm_test.cpp: undefined reference to `boost::test_tools::tt_detail::check_impl(boost::test_tools:: predicate_result const&, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)' /tmp/ccytTZBu.o(.text+0x173): In function `init_unit_test_suite(int, char*)':
You need to link with the pre-built standalone library. Use either Jam with Boost.Build system to build the library or you could use your own make system. But in that case you will need to come up with makefile yourself. The framework doesn't need much special compilation flags. Consult docs and Jam for more details.
Yeah, the docs are quite explicit about the need to link with the libs. Your Makefile could be as simple as:
CXXFLAGS= -I/usr/local/include LDFLAGS= -L/usr/local/lib -lboost_filesystem -lboost_program_options
These does not look right . I don;t think you need program options or filesystem to build a unbit test framework *library* ;)
Gennadiy
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Bobby Ward ------------------------------ bobbyrward@gmail.com http://sf.net/projects/combustion

# gennadiy.rozental@thomson.com / 2006-08-01 12:08:12 -0400:
"Roman Neuhauser" <neuhauser@sigpipe.cz> wrote in message news:20060801165504.GB8222@dagan.sigpipe.cz...
# gennadiy.rozental@thomson.com / 2006-08-01 10:44:48 -0400:
"Minkoo Seo" <minkoo.seo@gmail.com> wrote in message news:loom.20060801T091530-365@post.gmane.org...
[linking errors]
Yeah, the docs are quite explicit about the need to link with the libs. Your Makefile could be as simple as:
CXXFLAGS= -I/usr/local/include LDFLAGS= -L/usr/local/lib -lboost_filesystem -lboost_program_options
These does not look right . I don;t think you need program options or filesystem to build a unbit test framework *library* ;)
Sorry, that's a leftover from copy&paste. B.PO is /not/ required to compile/link a test suite. -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991
participants (4)
-
Bobby Ward
-
Gennadiy Rozental
-
Minkoo Seo
-
Roman Neuhauser