railsでmysqlを使おうと思い、mysql2をgemで設定
$ bundle install
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/ruby
--with-mysql-config
--without-mysql-config
Gem files will remain installed in /home/rails/.bundler/tmp/5253/gems/mysql2-0.3.11 for inspection.
Results logged to /home/rails/.bundler/tmp/5253/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
mysql.hが読み込まれない
mysql.hのファイルの場所は
/usr/local/mysql/include/mysql.h
なので、includeを設定
$ gem install mysql2 -- --with-opt-include=/usr/local/mysql/include
Building native extensions with: '--with-opt-include=/usr/local/mysql/include'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb --with-opt-include=/usr/local/mysql/include
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling result.c
./mysql2_ext.h:39 から include されたファイル中,
result.c:1 から:
./client.h:42:7: 警告: ファイル末尾に改行がありません
result.c: In function ‘rb_mysql_result_fetch_row’:
result.c:186: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
result.c: In function ‘rb_mysql_result_fetch_fields’:
result.c:381: 警告: 符合付きと符合無しとの比較です
compiling client.c
./mysql2_ext.h:39 から include されたファイル中,
client.c:1 から:
./client.h:42:7: 警告: ファイル末尾に改行がありません
client.c: In function ‘rb_raise_mysql2_error’:
client.c:98: 警告: ISO C90 forbids mixed declarations and code
client.c: In function ‘rb_connect’:
client.c:215: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c:219: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c: In function ‘rb_mysql_client_close’:
client.c:238: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c: In function ‘do_send_query’:
client.c:261: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c: In function ‘rb_mysql_client_async_result’:
client.c:309: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c:315: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c: In function ‘rb_mysql_client_socket’:
client.c:590: 警告: ISO C90 forbids mixed declarations and code
client.c: In function ‘rb_mysql_client_ping’:
client.c:636: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
client.c: In function ‘init_connection’:
client.c:728: 警告: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:835)
compiling mysql2_ext.c
./mysql2_ext.h:39 から include されたファイル中,
mysql2_ext.c:1 から:
./client.h:42:7: 警告: ファイル末尾に改行がありません
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld はステータス 1 で終了しました
make: *** [mysql2.so] エラー 1
Gem files will remain installed in /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
lib群も一緒に読み込ませた。
$ gem install mysql2 -- --with-opt-include=/usr/local/mysql/include --with-opt-lib=/usr/local/mysql/lib
Building native extensions with: '--with-opt-include=/usr/local/mysql/include --with-opt-lib=/usr/local/mysql/lib'
This could take a while...
Successfully installed mysql2-0.3.11
Parsing documentation for mysql2-0.3.11
unable to convert "\xA0" from ASCII-8BIT to UTF-8 for lib/mysql2/mysql2.so, skipping
Installing ri documentation for mysql2-0.3.11
1 gem installed
成功