mysql++にハマる

mysql++が2.*から3.*にバージョンアップされていたので,こちらのシステムもバージョンアップしようとしたら,何重にもハマってしまいました.

まず,コンパイルからしてハマりました.
gccだとコンパイルできるのですが,iccを使いたかったのですね.それで,

# export CC=icc
# export CXX=icc
# ./configure --enable-thread-check --with-mysl=/usr/local/mysql
# make

とすると,次のような初歩的なエラーがでました.

/mysql++-3.0.2/bk-deps icc -c -o mysqlpp_beemutex.o -I. -KPIC -DPIC -pthread -I/usr/local/mysql/include -g -O2 ./lib/beemutex.cpp
icc: command line remark #10148: option '-K' not supported
./lib/exceptions.h(182): error: namespace "std" has no member "type_info"
explicit BadOption(const char* w, const std::type_info& ti) :
^
./lib/exceptions.h(189): error: namespace "std" has no member "type_info"
explicit BadOption(const std::string& w, const std::type_info& ti) :
^
./lib/exceptions.h(199): error: namespace "std" has no member "type_info"
const std::type_info& what_option() const { return ti_; }
^
./lib/exceptions.h(202): error: namespace "std" has no member "type_info"
const std::type_info& ti_;

gccだと通るのに...type_infoが定義されていないって...
強引主義なので,mysql++-3.0.2/lib/common.hに,無理矢理typeinfoヘッダファイルを読みに行くように書き込みました.

#if !defined(MYSQLPP_COMMON_H)
#define MYSQLPP_COMMON_H
#include

これで大体のコンパイルは通るのですが,最後のtestプログラムのところでまたエラーが.

icc -o test_cpool test_cpool_cpool.o -L/usr/local/mysql/lib -L. -lz -lmysqlclient_r -lm
ysqlpp -lz
ld: Dwarf Error: mangled line number section (bad file number).

test_cpool_cpool.o: In function `main':
/usr/include/c++/4.1.2/ext/new_allocator.h:107: undefined reference to `std::cerr'
test_cpool_cpool.o: In function `main':
./test/cpool.cpp:(.text+0x96): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)'
./test/cpool.cpp:(.text+0xa4): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
./test/cpool.cpp:(.text+0xac): undefined reference to `std::ostream::operator<<(std::ostream&
(*)(std::ostream&))'
./test/cpool.cpp:(.text+0x106): undefined reference to `operator delete(void*)'
./test/cpool.cpp:(.text+0x129): undefined reference to `__dynamic_cast'
./test/cpool.cpp:(.text+0x17f): undefined reference to `__dynamic_cast'
./test/cpool.cpp:(.text+0x199): undefined reference to `std::cerr'

これは標準ライブラリがリンクされていないだけなので,環境変数をセットして,もう一度configureからやり直して,コンパイルが終わりました.

# export LDFLAGS="-lstdc++"
# # ./configure --enable-thread-check --with-mysl=/usr/local/mysql
# make
# make install
# ldconfig

これでインストールはできたのですが,mysql++を使ったプログラムを,新しいmysql++-3とリンクさせるためにコンパイルし直すと,またエラーが続出.mysql++の2と3では互換性が無く,詳しくはオフィシャルサイトに書かれています.
MySQL++: MySQL++

9. Incompatible Library Changes

This chapter documents those library changes since the epochal 1.7.9 release that break end-user programs. You can dig this stuff out of the ChangeLog, but the ChangeLog focuses more on explaining and justifying the facets of each change, while this section focuses on how to migrate your code between these library versions.

Since pure additions do not break programs, those changes are still documented only in the ChangeLog.
9.1. API Changes
(中略)
v3.0.0
Class name changes

Several classes changed names in this release:
ColData is now String.
NullisBlank is now NullIsBlank. (Note the capital I.) Similar changes for NullisNull and NullisZero.
ResNSel is now SimpleResult.
Result is now StoreQueryResult.
ResUse is now UseQueryResult.
SQLString is now SQLTypeAdapter.
(以下,大量.略.)

大半は,単に名前の置換で新バージョンに対応させることができました.
プログラムの書き換えが必要だったところは,文字列の取り出し関係のところです.
例えば,バージョン2系列だと

mysqlpp::Result result = query.store();
mysqlpp::row = result.at(0);
string res = row.at(0);

と書けていたとのが,mysqlpp自体にStringクラスが入ったので,row.at(0)がstd::stringクラスじゃなくてmysqlpp::Stringクラスなので,エラーが出ます.これは,こんな感じに書き直さなければなりませんでした.

mysqlpp::StoreQueryResult result = query.store();
mysqlpp::row = result.at(0);
string res;
row.at(0).to_string(res);

ふー.