Solaris11.1にDBD::mysqlをインストール(追記あり)
Solaris11.1にHRForecastをインストール - 部屋を掃除したら漫画が沢山出てきたので書く日記で行った、DBD::mysqlのインストールについてです。これがかなりハマりました。
※2014年4月2日追記
cpanmを実行する前に
PATH=/opt/solarisstudio12.3/bin
というようにSolarisStudioをインストールした上でPATHに設定してやれば、下記で説明している作業をする事なくインストールに成功するようです。
事情があってSolarisStudio使えない方は以下の手順で頑張ってみてください。
まず、上記の記事に書いた通り、HRForecast用関連CPANモジュールをインストールしていたところ、
Building DBD-mysql-4.025 ... FAIL
と出力され、DBD::mysqlのビルドに失敗している事がわかりました。
cpanmのbuild.logから関連個所だけを抜粋すると、以下のようになります。
Searching DBD::mysql on cpanmetadb ... --> Working on DBD::mysql Fetching http://www.cpan.org/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.025.tar.gz -> OK Unpacking DBD-mysql-4.025.tar.gz Entering DBD-mysql-4.025 Checking configure dependencies from META.yml Checking if you have DBI 1.08 ... Yes (1.630) Configuring DBD-mysql-4.025 Running Makefile.PL Can't exec "mysql_config": No such file or directory at Makefile.PL line 70. Cannot find the file 'mysql_config'! Your execution PATH doesn't seem not contain the path to mysql_config. Resorting to guessed values! Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located PLEASE NOTE: For 'make test' to run properly, you must ensure that the database user 'bata64' can connect to your MySQL server and has the proper privileges that these tests require such as 'drop table', 'create table', 'drop procedure', 'create procedure' as well as others. mysql> grant all privileges on test.* to 'bata64'@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 473. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located I will use the following settings for compiling and testing: cflags (guessed) = -I/usr/local/mysql/include embedded (guessed) = libs (guessed) = -L/usr/local/mysql/lib -lmysqlclient -lz -lm -lcrypt -lnsl mysql_config (guessed) = mysql_config nocatchstderr (default) = 0 nofoundrows (default) = 0 ssl (guessed) = 0 testdb (default) = test testhost (default) = testpassword (default) = testport (default) = testsocket (default) = testuser (guessed) = bata64 To change these settings, see 'perl Makefile.PL --help' and 'perldoc DBD::mysql::INSTALL'. Checking if your kit is complete... Warning: the following files are missing in your kit: META.json t/mem_leak.pl Please inform the author. Using DBI 1.63 (for perl 5.018001 on i86pc-solaris) installed in /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1/i86pc-solaris/auto/DBI/ Writing Makefile for DBD::mysql Writing MYMETA.yml and MYMETA.json -> OK Checking dependencies from MYMETA.json ... Checking if you have Test::More 0 ... Yes (0.98) Checking if you have Data::Dumper 0 ... Yes (2.145) Checking if you have Test::Deep 0 ... Yes (0.110) Checking if you have DBI 1.08 ... Yes (1.630) Building DBD-mysql-4.025 cp lib/DBD/mysql/INSTALL.pod blib/lib/DBD/mysql/INSTALL.pod cp README.pod blib/lib/DBD/README.pod cp lib/DBD/mysql.pm blib/lib/DBD/mysql.pm cp lib/DBD/mysql/GetInfo.pm blib/lib/DBD/mysql/GetInfo.pm cp lib/Bundle/DBD/mysql.pm blib/lib/Bundle/DBD/mysql.pm cc -c -I/export/home/bata64/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1/i86pc-solaris/auto/DBI -I/usr/local/mysql/include -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPERL_USE_SAFE_PUTENV -O -DVERSION=\"4.025\" -DXS_VERSION=\"4.025\" -fPIC "-I/export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/i86pc-solaris/CORE" dbdimp.c dbdimp.c: In function ‘mysql_describe’: dbdimp.c:3661:22: warning: assignment from incompatible pointer type /export/home/bata64/.plenv/versions/5.18.1/bin/perl5.18.1 -p -e "s/~DRIVER~/mysql/g" /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1/i86pc-solaris/auto/DBI/Driver.xst > mysql.xsi /export/home/bata64/.plenv/versions/5.18.1/bin/perl5.18.1 /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/ExtUtils/xsubpp -typemap /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/ExtUtils/typemap mysql.xs > mysql.xsc && mv mysql.xsc mysql.c Warning: duplicate function definition 'do' detected in mysql.xs, line 242 Warning: duplicate function definition 'rows' detected in mysql.xs, line 754 cc -c -I/export/home/bata64/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1/i86pc-solaris/auto/DBI -I/usr/local/mysql/include -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPERL_USE_SAFE_PUTENV -O -DVERSION=\"4.025\" -DXS_VERSION=\"4.025\" -fPIC "-I/export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/i86pc-solaris/CORE" mysql.c Running Mkbootstrap for DBD::mysql () chmod 644 mysql.bs rm -f blib/arch/auto/DBD/mysql/mysql.so LD_RUN_PATH="/usr/local/mysql/lib:/usr/local/lib:/usr/lib" /export/home/bata64/.plenv/versions/5.18.1/bin/perl5.18.1 myld cc -shared -L/usr/local/lib -L/usr/gnu/lib -fstack-protector dbdimp.o mysql.o -o blib/arch/auto/DBD/mysql/mysql.so \ -L/usr/local/mysql/lib -lmysqlclient -lz -lm -lcrypt -lnsl \ ld: fatal: file /usr/local/mysql/lib/libmysqlclient.so: wrong ELF class: ELFCLASS64 ld: fatal: file processing errors. No output written to blib/arch/auto/DBD/mysql/mysql.so collect2: ld returned 1 exit status make: *** [blib/arch/auto/DBD/mysql/mysql.so] エラー 1 -> FAIL Installing DBD::mysql failed. See /export/home/bata64/.cpanm/work/1383915723.15226/build.log for details. Retry with --force to force install it. -> FAIL Installing the dependencies failed: Module 'DBD::mysql' is not installed -> FAIL Bailing out the installation for HRForecast-0.01. 2 distributions installed
ここから気づいた事は、
- 「Can't exec "mysql_config": No such file or directory at Makefile.PL line 70.」というような、mysql_configが見つからないというエラーがたくさん出ていること
と、
- 「ld: fatal: file /usr/local/mysql/lib/libmysqlclient.so: wrong ELF class: ELFCLASS64」というエラーが出ている
という事でした。
まず、一つ目の方を解決しようと思います。いろいろ調べた結果、cpanmで以下のようなオプションにしてやれば、mysql_configが参照させることができます。
cpanm DBD::mysql -L extlib -n --configure-args="CC=gcc --mysql_config=/usr/mysql/bin/mysql_config
実行してみたところ、一つ目のエラーは表示されなくなりました。さらに、二つ目も表示されなくなりました。
二つ目は、シェアードライブラリが64bitである/usr/local/mysql/lib/libmysqlclient.soに、32bitのものでアクセスしたために起きていると思われます。
調べると、マイサーバには
/usr/bin/mysql
と
/usr/local/bin/mysql
がインストールされており、私は前者を使うつもりだったのですが、mysql_configが参照できない場合だと後者を参照しようとするオプションでビルドしようとしていて、かつ前者は32bit版mysqlであるものの、後者は64bit版だった、という事も判明しました。
という事で、使いたい32bit版mysqlを使用するようなオプションをつける事でこれらのエラーはでなくなりましたが、今度は以下のようなエラーが出力されるようになりました。
$ cpanm DBD::mysql -L extlib -n --configure-args="CC=gcc --mysql_config=/usr/mysql/bin/mysql_config" --> Working on DBD::mysql Fetching http://www.cpan.org/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.025.tar.gz ... OK Configuring DBD-mysql-4.025 ... OK Building DBD-mysql-4.025 ... FAIL ! Installing DBD::mysql failed. See /export/home/bata64/.cpanm/work/1383920312.20056/build.log for details. Retry with --force to force install it.
build.logは以下の通りです。
bata64@tpc5160:tmp[23:19:07]$ cat /export/home/bata64/.cpanm/work/1383920312.20056/build.log cpanm (App::cpanminus) 1.7001 on perl 5.018001 built for i86pc-solaris Work directory is /export/home/bata64/.cpanm/work/1383920312.20056 You have make /usr/gnu/bin/make You have LWP 6.05 You have /usr/gnu/bin/tar, /usr/bin/gzip and /usr/bin/bzip2 You have /usr/bin/unzip Checking if you have ExtUtils::MakeMaker 6.31 ... Yes (6.66) Checking if you have ExtUtils::Install 1.46 ... Yes (1.59) Searching DBD::mysql on cpanmetadb ... --> Working on DBD::mysql Fetching http://www.cpan.org/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.025.tar.gz -> OK Unpacking DBD-mysql-4.025.tar.gz Entering DBD-mysql-4.025 Checking configure dependencies from META.yml Checking if you have DBI 1.08 ... Yes (1.630) Configuring DBD-mysql-4.025 Running Makefile.PL PLEASE NOTE: For 'make test' to run properly, you must ensure that the database user 'bata64' can connect to your MySQL server and has the proper privileges that these tests require such as 'drop table', 'create table', 'drop procedure', 'create procedure' as well as others. mysql> grant all privileges on test.* to 'bata64'@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username I will use the following settings for compiling and testing: cflags (mysql_config) = -I/usr/mysql/include/mysql -m32 -xchip=pentium -xregs=no%frameptr -mt -xprefetch=auto -xprefetch_level=3 -fns=no -fsimple=1 -xbuiltin=%none -xlibmil -xlibmopt -xnorunpath -DHAVE_RWLOCK_T -DUNIV_SOLARIS embedded (mysql_config) = ldflags (mysql_config) = -R/usr/mysql/5.1/lib/mysql libs (mysql_config) = -L/usr/mysql/5.1/lib/mysql -lmysqlclient -lz -lsocket -lnsl -lm mysql_config (Users choice) = /usr/mysql/bin/mysql_config nocatchstderr (default ) = 0 nofoundrows (default ) = 0 ssl (guessed ) = 0 testdb (default ) = test testhost (default ) = testpassword (default ) = testport (default ) = testsocket (default ) = testuser (guessed ) = bata64 To change these settings, see 'perl Makefile.PL --help' and 'perldoc DBD::mysql::INSTALL'. Checking if your kit is complete... Warning: the following files are missing in your kit: META.json t/mem_leak.pl Please inform the author. Multiple copies of Driver.xst found in: /tmp/extlib/lib/perl5/i86pc-solaris/auto/DBI/ /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/site_perl/5.18.1/i86pc-solaris/auto/DBI/ at Makefile.PL line 936. Using DBI 1.63 (for perl 5.018001 on i86pc-solaris) installed in /tmp/extlib/lib/perl5/i86pc-solaris/auto/DBI/ Writing Makefile for DBD::mysql Writing MYMETA.yml and MYMETA.json -> OK Checking dependencies from MYMETA.json ... Checking if you have Data::Dumper 0 ... Yes (2.145) Checking if you have Test::Deep 0 ... Yes (0.110) Checking if you have DBI 1.08 ... Yes (1.630) Checking if you have Test::More 0 ... Yes (0.98) Building DBD-mysql-4.025 cp lib/DBD/mysql/GetInfo.pm blib/lib/DBD/mysql/GetInfo.pm cp lib/Bundle/DBD/mysql.pm blib/lib/Bundle/DBD/mysql.pm cp lib/DBD/mysql.pm blib/lib/DBD/mysql.pm cp lib/DBD/mysql/INSTALL.pod blib/lib/DBD/mysql/INSTALL.pod cp README.pod blib/lib/DBD/README.pod gcc -c -I/tmp/extlib/lib/perl5/i86pc-solaris/auto/DBI -I/usr/mysql/include/mysql -m32 -xchip=pentium -xregs=no%frameptr -mt -xprefetch=auto -xprefetch_level=3 -fns=no -fsimple=1 -xbuiltin=%none -xlibmil -xlibmopt -xnorunpath -DHAVE_RWLOCK_T -DUNIV_SOLARIS -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPERL_USE_SAFE_PUTENV -O -DVERSION=\"4.025\" -DXS_VERSION=\"4.025\" -fPIC "-I/export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/i86pc-solaris/CORE" dbdimp.c gcc: language norunpath not recognized gcc: language norunpath not recognized gcc: dbdimp.c: linker input file unused because linking not done /export/home/bata64/.plenv/versions/5.18.1/bin/perl5.18.1 -p -e "s/~DRIVER~/mysql/g" /tmp/extlib/lib/perl5/i86pc-solaris/auto/DBI/Driver.xst > mysql.xsi /export/home/bata64/.plenv/versions/5.18.1/bin/perl5.18.1 /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/ExtUtils/xsubpp -typemap /export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/ExtUtils/typemap mysql.xs > mysql.xsc && mv mysql.xsc mysql.c Warning: duplicate function definition 'do' detected in mysql.xs, line 242 Warning: duplicate function definition 'rows' detected in mysql.xs, line 754 gcc -c -I/tmp/extlib/lib/perl5/i86pc-solaris/auto/DBI -I/usr/mysql/include/mysql -m32 -xchip=pentium -xregs=no%frameptr -mt -xprefetch=auto -xprefetch_level=3 -fns=no -fsimple=1 -xbuiltin=%none -xlibmil -xlibmopt -xnorunpath -DHAVE_RWLOCK_T -DUNIV_SOLARIS -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DPERL_USE_SAFE_PUTENV -O -DVERSION=\"4.025\" -DXS_VERSION=\"4.025\" -fPIC "-I/export/home/bata64/.plenv/versions/5.18.1/lib/perl5/5.18.1/i86pc-solaris/CORE" mysql.c gcc: language norunpath not recognized gcc: language norunpath not recognized gcc: mysql.c: linker input file unused because linking not done Running Mkbootstrap for DBD::mysql () chmod 644 mysql.bs rm -f blib/arch/auto/DBD/mysql/mysql.so LD_RUN_PATH="/usr/mysql/5.1/lib/mysql:/usr/local/lib" /export/home/bata64/.plenv/versions/5.18.1/bin/perl5.18.1 myld cc -shared -L/usr/local/lib -L/usr/gnu/lib -fstack-protector dbdimp.o mysql.o -o blib/arch/auto/DBD/mysql/mysql.so \ -L/usr/mysql/5.1/lib/mysql -lmysqlclient -lz -lsocket -lnsl -lm \ cc: dbdimp.o: No such file or directory cc: mysql.o: No such file or directory make: *** [blib/arch/auto/DBD/mysql/mysql.so] エラー 1 -> FAIL Installing DBD::mysql failed. See /export/home/bata64/.cpanm/work/1383920312.20056/build.log for details. Retry with --force to force install it.
ここで着目したのは、
gcc: language norunpath not recognized
というメッセージと、
cc: dbdimp.o: No such file or directory cc: mysql.o: No such file or directory
というメッセージです。
前者はdbdimp.o、mysql.oを生成するgccコマンドの行でそれぞれ出力されている事から、このためにこれらのオブジェクトファイルが生成されないのでは、と考えました。
で、またまたいろいろ調べた結果、「language norunpath not recognized」というメッセージは、その上の行のgccのオプションのうち、「-xprefetch」があるために出ているようでした。
そこで、cpanmの作業ディレクトリである
~/.cpanm/latest-build/DBD-mysql-4.025
に移動して、直接ビルドしてみる事にしました。
ログには
cflags (mysql_config) = -I/usr/mysql/include/mysql -m32 -xchip=pentium -xregs=no%frameptr -mt -xprefetch=auto -xprefetch_level=3 -fns=no -fsimple=1 -xbuiltin=%none -xlibmil -xlibmopt -xnorunpath -DHAVE_RWLOCK_T -DUNIV_SOLARIS
というように「cflags」として該当のオプションが渡されているようでしたので、上記から「-xnorunpath」を除いて、
perl Makefile.PL CC=gcc --mysql_config=/usr/mysql/bin/mysql_config --cflags="-I/usr/mysql/include/mysql -m32 -xchip=pentium -xregs=no%frameptr -mt -xprefetch=auto -xprefetch_level=3 -fns=no -fsimple=1 -xbuiltin=%none -xlibmil -xlibmopt -DHAVE_RWLOCK_T -DUNIV_SOLARIS"
と実行後、
make
を実行してみました。
すると「language norunpath not recognized」は出力されなくなりましたが、今度は別のオプションに関して「language ~ not recognized」が出力されるようになりました。
こうして、出力されるオプションを一つづつ取り除いてやり、エラーが出なくなるまでperl Makefile.PLおよびmakeを繰り返した結果、
perl Makefile.PL CC=gcc --mysql_config=/usr/mysql/bin/mysql_config --with-mysql=/usr/mysql/5.1 --cflags="-I/usr/mysql/include/mysql -m32 -DHAVE_RWLOCK_T -DUNIV_SOLARIS"
とすればmakeに成功する事がわかりました。
なお、「--with-mysql=/usr/mysql/5.1」は冗長かもしれませんが調べ物をしたサイトに書いてあったので書いてみました。
で、このあと
make test
を行うとテストに失敗するのですが、ビルドに成功したからもういいや!と思い、このオプションをcpanmに以下のように渡し、インストールに成功する事が出来ました。
cpanm DBD::mysql -L extlib -n --configure-args="CC=gcc --mysql_config=/usr/mysql/bin/mysql_config --with-mysql=/usr/mysql/5.1 --cflags=\"-I/usr/mysql/include/mysql -m32 -DHAVE_RWLOCK_T -DUNIV_SOLARIS\""
その後はSolaris11.1にHRForecastをインストール - 部屋を掃除したら漫画が沢山出てきたので書く日記の通りです。あー疲れた・・・。しかしいい勉強でした。
ではー。