6

I'm using gcc 4.8.2 with Boost 1.59. I run on Kubuntu 12.04 LTS. I'm just trying to write a simple unit test application and I'm experiencing linker error.

Here is my code:

main.cpp

#define BOOST_TEST_MODULE My Module
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

test1.cpp

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( suite1 );
BOOST_AUTO_TEST_CASE( case1 )
{
    BOOST_TEST_MESSAGE( "Hello!" );
}
BOOST_AUTO_TEST_SUITE_END();

When I build I do: g++ -std=c++11 -o test main.cpp test1.cpp -I/usr/local/include -L/usr/local/lib -lboost_unit_test_framework. And I get this result:

/tmp/ccmNLUMx.o: In function `__static_initialization_and_destruction_0(int, int)':
test1.cpp:(.text+0x15e): undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char const>)'
test1.cpp:(.text+0x1b9): undefined reference to `boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, unsigned long)'
/tmp/ccmNLUMx.o: 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>)':
test1.cpp: (.text._ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE[_ZN5boost9unit_test14make_test_caseERKNS0_9callback0INS0_9ut_detail6unusedEEENS0_13basic_cstringIKcEE]+0x6d): 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: erreur: ld a retourné 1 code d'état d'exécution

Do you have any idea about what I'm doing wrong? Thanks!

Dominique

EDIT

What is given here could not solve my problem... :-(

Community
  • 1
  • 1
dom_beau
  • 2,437
  • 3
  • 30
  • 59
  • Can you please post the command to compile that you tried after trying the solution in the link you posted in the EDIT section? – jayant Nov 11 '15 at 06:04
  • @jayant I took it "successful" command: `g++ -I/usr/local/include -o test main.cpp -L/usr/local/lib -Wl,-Bdynamic -lboost_unit_test_framework`. Same error. It looks there is something missing. The author uses Boost 1.52, I use 1.59. I built it myself from the source code... I'm pretty confused because I could easily build tests few years ago with previous version of Boost. I'm not saying that there is a bug with 1.59 but rather than my 1.59 installation is maybe wrong??? – dom_beau Nov 11 '15 at 13:10
  • I found the solution, see [this post](http://stackoverflow.com/questions/33644914/boost-test-cannot-find-main/33659967#33659967). – dom_beau Nov 11 '15 at 21:15

2 Answers2

16

I had the same problem. My solution is, change the include path:

#include <boost/test/unit_test.hpp> // wrong  
#include <boost/test/included/unit_test.hpp> // this work

I had found the solution in the first example of boost unit test. I test it with boost 1.60 and gcc 4.8.5

SebastianH
  • 734
  • 5
  • 23
0

Adding -D_GLIBCXX_USE_CXX11_ABI=0 to compile options resolved this for me

Evgen
  • 194
  • 1
  • 11