Linking errors while using the test library (for a very basic program)
I have a very simple program
********************************************************************
#include <iostream>
#include
Josh wrote:
I have a very simple program ******************************************************************** #include <iostream> #include
using boost::unit_test::test_suite; void MyTest() { BOOST_CHECK(2==2); }
test_suite * init_unit_test_suite( int, char* [] ) { test_suite* test= BOOST_TEST_SUITE( "Simple test" ); test->add(BOOST_TEST_CASE( &MyTest ), 0); return test; } **************************************************************************************** I am trying to compile it using the following commands
g++ -c BoostTest.cpp -I~/boost/include/boost-1_33_1/ g++ -o BT BoostTest.o -I/home/josh/boost/include/boost-1_33_1/ /home/josh/boost/lib/libboost_unit_test_framework-gcc-s.a
The first step completes without a problem, the linking stage gives the following errors
BoostTest.o(.text+0x15b): In function `MyTest()': : undefined reference to `boost::test_tools::tt_detail::test_and_continue_impl(bool, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned int, bool, boost::unit_test::log_level)' BoostTest.o(.text+0x258): In function `init_unit_test_suite(int, char**)': : undefined reference to `boost::unit_test::test_suite::add(boost::unit_test::test_case*, unsigned long, int)' BoostTest.o(.gnu.linkonce.t._ZN5boost9unit_test16create_test_caseEPFvvESs+0x12): In function `boost::unit_test::create_test_case(void (*)(), std::basic_string
)': : undefined reference to `boost::unit_test::ut_detail::normalize_test_case_name(std::basic_string &)' BoostTest.o(.gnu.linkonce.t._ZN5boost9unit_test18function_test_caseC1EPFvvENS0_13basic_cstringIKcEE+0x1b): In function `boost::unit_test::function_test_case::function_test_case(void (*)(), boost::unit_test::basic_cstring<char const>)': : undefined reference to `boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, bool, unsigned long, bool)' BoostTest.o(.gnu.linkonce.r._ZTVN5boost9unit_test18function_test_caseE+0x10): undefined reference to `boost::unit_test::test_case::size() const' BoostTest.o(.gnu.linkonce.t._ZN5boost9unit_test9test_caseD2Ev+0xc): In function `boost::unit_test::test_case::~test_case()': : undefined reference to `vtable for boost::unit_test::test_case' BoostTest.o(.gnu.linkonce.r._ZTIN5boost9unit_test18function_test_caseE+0x8): undefined reference to `typeinfo for boost::unit_test::test_case' *************************************************************
PLEASE HELP! Josh
I just had a very similar problem. I have been using the library fine under Visual Studio, and I am trying to test my code on Linux now. Any help would be greatly appreciated. Thanks, Ed g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1) Fedora 5 [root@localhost src]# make check Making check in . make[1]: Entering directory `/root/Desktop/hivm_svn_test/trunk/src' make testhivm make[2]: Entering directory `/root/Desktop/hivm_svn_test/trunk/src' g++ -g -O2 -o testhivm BioProcessor.o Client.o CrossValidationExperiment.o ExperimentAnalyzer.o ExperimentResult.o FileIO.o FunctionObjects.o LibSvmAdapter.o Log.o Options.o PreProcWorkUnit.o PreProcessor.o SelfTestExperiment.o SvmMachine.o SvmWorkUnit.o ValidationExperiment.o dpl.o svm.o ./3rd_party/boost/lib/* -L./3rd_party/boost/lib/libboost_unit_test_framework-gcc-mt-d-1_33_1.a make[2]: Leaving directory `/root/Desktop/hivm_svn_test/trunk/src' make[1]: Leaving directory `/root/Desktop/hivm_svn_test/trunk/src' ./3rd_party/boost/lib/libboost_unit_test_framework-gcc-mt-d-1_33_1.a(framework.o): In function `boost::unit_test::framework::init(int, char**)': /root/Desktop/boost_1_33_1/boost/test/impl/framework.ipp:192: undefined reference to `init_unit_test_suite(int, char**)' collect2: ld returned 1 exit status make[2]: *** [testhivm] Error 1 make[1]: *** [check-am] Error 2 make: *** [check-recursive] Error 1
Ed Johnson wrote:
Josh wrote:
I have a very simple program ******************************************************************** #include <iostream> #include
using boost::unit_test::test_suite; void MyTest() { BOOST_CHECK(2==2); }
test_suite * init_unit_test_suite( int, char* [] ) { test_suite* test= BOOST_TEST_SUITE( "Simple test" ); test->add(BOOST_TEST_CASE( &MyTest ), 0); return test; } **************************************************************************************** I am trying to compile it using the following commands
g++ -c BoostTest.cpp -I~/boost/include/boost-1_33_1/ g++ -o BT BoostTest.o -I/home/josh/boost/include/boost-1_33_1/ /home/josh/boost/lib/libboost_unit_test_framework-gcc-s.a
The first step completes without a problem, the linking stage gives the following errors
BoostTest.o(.text+0x15b): In function `MyTest()': : undefined reference to `boost::test_tools::tt_detail::test_and_continue_impl(bool, boost::basic_wrap_stringstream<char>&, boost::unit_test::basic_cstring<char const>, unsigned int, bool, boost::unit_test::log_level)' BoostTest.o(.text+0x258): In function `init_unit_test_suite(int, char**)': : undefined reference to `boost::unit_test::test_suite::add(boost::unit_test::test_case*, unsigned long, int)' BoostTest.o(.gnu.linkonce.t._ZN5boost9unit_test16create_test_caseEPFvvESs+0x12): In function `boost::unit_test::create_test_case(void (*)(), std::basic_string
)': : undefined reference to `boost::unit_test::ut_detail::normalize_test_case_name(std::basic_string &)' BoostTest.o(.gnu.linkonce.t._ZN5boost9unit_test18function_test_caseC1EPFvvENS0_13basic_cstringIKcEE+0x1b): In function `boost::unit_test::function_test_case::function_test_case(void (*)(), boost::unit_test::basic_cstring<char const>)': : undefined reference to `boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, bool, unsigned long, bool)' BoostTest.o(.gnu.linkonce.r._ZTVN5boost9unit_test18function_test_caseE+0x10): undefined reference to `boost::unit_test::test_case::size() const' BoostTest.o(.gnu.linkonce.t._ZN5boost9unit_test9test_caseD2Ev+0xc): In function `boost::unit_test::test_case::~test_case()': : undefined reference to `vtable for boost::unit_test::test_case' BoostTest.o(.gnu.linkonce.r._ZTIN5boost9unit_test18function_test_caseE+0x8): undefined reference to `typeinfo for boost::unit_test::test_case' *************************************************************
PLEASE HELP! Josh
I just had a very similar problem. I have been using the library fine under Visual Studio, and I am trying to test my code on Linux now.
Any help would be greatly appreciated.
Thanks,
Ed
g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1) Fedora 5
[root@localhost src]# make check Making check in . make[1]: Entering directory `/root/Desktop/hivm_svn_test/trunk/src' make testhivm make[2]: Entering directory `/root/Desktop/hivm_svn_test/trunk/src' g++ -g -O2 -o testhivm BioProcessor.o Client.o CrossValidationExperiment.o ExperimentAnalyzer.o ExperimentResult.o FileIO.o FunctionObjects.o LibSvmAdapter.o Log.o Options.o PreProcWorkUnit.o PreProcessor.o SelfTestExperiment.o SvmMachine.o SvmWorkUnit.o ValidationExperiment.o dpl.o svm.o ./3rd_party/boost/lib/* -L./3rd_party/boost/lib/libboost_unit_test_framework-gcc-mt-d-1_33_1.a make[2]: Leaving directory `/root/Desktop/hivm_svn_test/trunk/src' make[1]: Leaving directory `/root/Desktop/hivm_svn_test/trunk/src'
./3rd_party/boost/lib/libboost_unit_test_framework-gcc-mt-d-1_33_1.a(framework.o): In function `boost::unit_test::framework::init(int, char**)': /root/Desktop/boost_1_33_1/boost/test/impl/framework.ipp:192: undefined reference to `init_unit_test_suite(int, char**)' collect2: ld returned 1 exit status make[2]: *** [testhivm] Error 1 make[1]: *** [check-am] Error 2 make: *** [check-recursive] Error 1
fyi, my problem turned out to be with my automake configuration. Everything is fine with the unit test libraries.
If we exclude error in a library, when symbol is actually missing, there are not so many reasons that may cause undefined symbol error:
1. Library is missing from link command
2. Library is binary incompatible with test module code. The reason could be: different compiler version or different compilation options used for library and test module.
3. For some compilers. library should be listed before object files that refer to it.
4. Library is built improperly. Some object files are missing, for example. Using nm command usually allows to detect this.
HTH.
Gennadiy
"Josh"
Josh wrote:
test->add(BOOST_TEST_CASE( &MyTest ), 0); [text unrelated to my reply trimmed... would others remember to do the same, please]
I don't know whether it would make any difference at all, but I don't see why the line above is written as shown and not as just: test->add(BOOST_TEST_CASE( MyTest ); (unless your form is an alternative syntax that I am not aware of). I don't known why you need the extra parameter - your function MyTest doesn't take any parameters, and in any case, these would be bound rather than passed directly.
Paul Giaccone wrote:
Josh wrote:
test->add(BOOST_TEST_CASE( &MyTest ), 0);
I don't know whether it would make any difference at all, but I don't see why the line above is written as shown and not as just:
test->add(BOOST_TEST_CASE( MyTest );
...before anyone points it out, there should of course be another close bracket.
"Paul Giaccone"
Josh wrote:
test->add(BOOST_TEST_CASE( &MyTest ), 0); [text unrelated to my reply trimmed... would others remember to do the same, please]
I don't know whether it would make any difference at all, but I don't see why the line above is written as shown and not as just:
test->add(BOOST_TEST_CASE( MyTest );
(unless your form is an alternative syntax that I am not aware of). I don't known why you need the extra parameter - your function MyTest doesn't take any parameters, and in any case, these would be bound rather than passed directly.
0 here is the number of expected errors. It's default value, but this is still a valid syntax. Gennadiy
participants (4)
-
Ed Johnson
-
Gennadiy Rozental
-
Josh
-
Paul Giaccone