boostのユニットテストはstaticリンクする

ousttrue2008-12-18

gentooにboost-1.37.0をソースからインストールしたのだがunit testがリンクできない事態に遭遇。

/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

http://lists.boost.org/boost-users/2007/11/32236.php
によると移植性の問題からどっかのバージョンからdynamicリンクにはmainが無くなったらしい。
あまり言及されているところが無くて調べるのに手間取った。
boostなのにリンクが要るから不人気なのか。


空のテスト
test.cpp

// 2008/12/20追記
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
// BOOST_CHECKでlinkエラー防止
#include <boost/test/included/unit_test.hpp>
// ここまで
#include <boost/test/unit_test.hpp>

boost::unit_test_framework::test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
  boost::unit_test_framework::test_suite* test= BOOST_TEST_SUITE( "const_string test" );
  return test;
}

staticの方をリンクする

$ g++ test.cpp -static -lboost_unit_test_framework-gcc43-mt-1_37


もうひとつ問題があってこれはgcc4.3の問題っぽいのだがこんなエラーが出る。

/usr/include/boost/test/test_tools.hpp:567: error: ‘CHAR_BIT’ was not declared in this scope

よくわからんがソース先頭に下記のようにしておいた。

#define CHAR_BIT 8

gcc-4.3はデンジャーゾーンなのか。