メモの日々


2010年01月06日(水) [長年日記]

  • 今日からちゃんとした仕事の始まり。
  • メインの仕事は再びC++に。

[c++] Ubuntu 9.10 での Boost 1.34.1 のコンパイルエラーとその対処

訳あってBoost 1.34 を使う必要がある(今の最新は1.41.0)。今まではUbuntuのパッケージにBoostのバージョン1.34があってそれを使っていたのだけれど、今日Ubuntuを9.10にアップグレードしたらもはやサポート外ということで古いバージョンのBoostは削除されてしまった(削除に同意したのは自分の判断)。

仕方ないので、1.34.1のソースをダウンロードして自分でコンパイルしてみた。

コンパイル手順

ダウンロードした boost_1_34_1.tar.bz2 を展開するとconfigureスクリプトがあるので、これを使えばよさそう。全てをビルドする必要はなかったので、

% ./configure --prefix=/home/kenichi/boost1.34 --with-libraries=test,thread,program_options

のようにしてtest, thread, program_optionsの3つだけをビルドするようにした。これでMakefileが作られるので、

% make

を実行すればよい。が、コンパイルエラーがたくさん出た。

コンパイルエラーの内容

エラーはたくさんあったが、よく見ると2種類のエラーしかない模様。ひとつは

error: 'CHAR_BIT' was not declared in this scope

というもの。このエラーは boost/test/test_tools.hpp だけで起きている。

もうひとつのエラーは

error: missing binary operator before token "("

というもの。これは boost/mpl/ 配下で発生。当該個所のソースは全て

#elif BOOST_PP_ITERATION_DEPTH() == 1

といったマクロ絡みの所。

コンパイルエラーへの対処

検索すると、後者のエラーはBoostのバグのようで、次のチケットがヒットした。

このチケットにあるようにエラー個所の #elif 部分を修正したらコンパイルできるようになった。

前者のエラーは、boost/test/test_tools.hpp に <climits> をincludeする修正をしたら直った。

以下に自分で加えた差分をメモ。

diff -u -r boost/mpl/apply.hpp ../boost_1_34_1_kenichi/boost/mpl/apply.hpp
--- boost/mpl/apply.hpp 2004-09-03 00:40:41.000000000 +0900
+++ ../boost_1_34_1_kenichi/boost/mpl/apply.hpp 2010-01-06 17:37:27.000000000 +0900
@@ -135,7 +135,8 @@

 ///// iteration, depth == 1

-#elif BOOST_PP_ITERATION_DEPTH() == 1
+#else
+#if BOOST_PP_ITERATION_DEPTH() == 1

 #   define i_ BOOST_PP_FRAME_ITERATION(1)

@@ -222,4 +223,5 @@

 #   undef i_

+#endif
 #endif // BOOST_PP_IS_ITERATING
diff -u -r boost/mpl/apply_wrap.hpp ../boost_1_34_1_kenichi/boost/mpl/apply_wrap.hpp
--- boost/mpl/apply_wrap.hpp    2004-09-04 00:56:55.000000000 +0900
+++ ../boost_1_34_1_kenichi/boost/mpl/apply_wrap.hpp    2010-01-06 17:35:47.000000000 +0900
@@ -78,7 +78,8 @@

 ///// iteration, depth == 1

-#elif BOOST_PP_ITERATION_DEPTH() == 1
+#else
+#if BOOST_PP_ITERATION_DEPTH() == 1

 #   define i_ BOOST_PP_FRAME_ITERATION(1)

@@ -197,4 +198,5 @@

 #   undef j_

+#endif
 #endif // BOOST_PP_IS_ITERATING
diff -u -r boost/mpl/aux_/full_lambda.hpp ../boost_1_34_1_kenichi/boost/mpl/aux_/full_lambda.hpp
--- boost/mpl/aux_/full_lambda.hpp      2004-09-04 10:10:19.000000000 +0900
+++ ../boost_1_34_1_kenichi/boost/mpl/aux_/full_lambda.hpp      2010-01-06 17:37:02.000000000 +0900
@@ -227,7 +227,8 @@

 ///// iteration, depth == 1

-#elif BOOST_PP_ITERATION_DEPTH() == 1
+#else
+#if BOOST_PP_ITERATION_DEPTH() == 1
 #define i_ BOOST_PP_FRAME_ITERATION(1)

 #if i_ > 0
@@ -347,4 +348,5 @@
 };

 #undef i_
+#endif
 #endif // BOOST_PP_IS_ITERATING
diff -u -r boost/mpl/bind.hpp ../boost_1_34_1_kenichi/boost/mpl/bind.hpp
--- boost/mpl/bind.hpp  2004-10-26 23:51:04.000000000 +0900
+++ ../boost_1_34_1_kenichi/boost/mpl/bind.hpp  2010-01-06 17:36:26.000000000 +0900
@@ -361,7 +361,8 @@

 ///// iteration, depth == 1

-#elif BOOST_PP_ITERATION_DEPTH() == 1
+#else
+#if BOOST_PP_ITERATION_DEPTH() == 1

 #   define i_ BOOST_PP_FRAME_ITERATION(1)

@@ -544,4 +545,5 @@
 #   endif
 #   undef j_

+#endif
 #endif // BOOST_PP_IS_ITERATING
diff -u -r boost/test/test_tools.hpp ../boost_1_34_1_kenichi/boost/test/test_tools.hpp
--- boost/test/test_tools.hpp   2007-02-23 02:57:29.000000000 +0900
+++ ../boost_1_34_1_kenichi/boost/test/test_tools.hpp   2010-01-06 17:42:16.000000000 +0900
@@ -42,6 +42,7 @@
 #include <boost/mpl/or.hpp>

 // STL
+#include <climits>
 #include <cstddef>          // for std::size_t
 #include <iosfwd>