Boost の autolink がやたらと鬱陶しい件
Visual Studio や Borland C++ 上で Boost を使ったことがなかったのでまったく意識したことがなかったんだけど、それらの toolset 用ビルドには autolink なるフィーチャーがある。通常、これらの toolset のリンカではユーザは明示的にインポートライブラリを指定する必要があるが、このフィーチャーは、pragma を使って暗黙的かつ自動的にリンカに必要なライブラリ名を与えるようになっている。
これにずっと気づかず、わけの分からないライブラリのリンケージに3日は悩んだ気が。設定ファイルやビルドファイルを FINDSTR しても、ライブラリ名 (例えば boost_python-vc80-mt-1_34.lib) に全く該当する文字列が見つからないからだ。まさかヘッダに書いてあるとは、普通は思わない。
boost/config/autolink.hpp より引用。
Algorithm:
~~~~~~~~~~
Libraries for Borland and Microsoft compilers are automatically
selected here, the name of the lib is selected according to the following
formula:
BOOST_LIB_PREFIX
+ BOOST_LIB_NAME
+ "_"
+ BOOST_LIB_TOOLSET
+ BOOST_LIB_THREAD_OPT
+ BOOST_LIB_RT_OPT
"-"
+ BOOST_LIB_VERSION
These are defined as:
BOOST_LIB_PREFIX: "lib" for static libraries otherwise "".
BOOST_LIB_NAME: The base name of the lib ( for example boost_regex).
BOOST_LIB_TOOLSET: The compiler toolset name (vc6, vc7, bcb5 etc).
BOOST_LIB_THREAD_OPT: "-mt" for multithread builds, otherwise nothing.
BOOST_LIB_RT_OPT: A suffix that indicates the runtime library used,
contains one or more of the following letters after
a hiphen:
s static runtime (dynamic if not present).
d debug build (release if not present).
g debug/diagnostic runtime (release if not present).
p STLPort Build.
BOOST_LIB_VERSION: The Boost version, in the form x_y, for Boost version x.y.で、bjam だけでビルドが完結する世界ならともかく、これは Visual Studio 上のビルドツールで使うには激しく鬱陶しい。せめてバージョン番号とか勝手につけるのをやめて欲しいとか思うわけだ。
バージョン番号等々は BOOST_AUTO_LINK_NOMANGLE というマクロを定義することで取り除くことができる。その場合、インポートライブラリの名前は BOOST_LIB_NAME のみになる。
それにしても、こんなことをしてもほとんどの人は喜ばないと思うんだけどなあ。。。