Failed to build gem native extension

Hello I am trying to run bundle install to an existing app that is built upon rails 4.2. but doing this, i am facing the same error.

ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.

i did try everything, but nothing works.

here is the full error.

Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/smehsan/.rbenv/versions/2.4.7/lib/ruby/gems/2.4.0/gems/mysql2-0.3.21/ext/mysql2
/home/smehsan/.rbenv/versions/2.4.7/bin/ruby -I
/home/smehsan/.rbenv/versions/2.4.7/lib/ruby/site_ruby/2.4.0 -r ./siteconf20200915-378544-rr782y.rb
extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting libpath to /usr/lib/x86_64-linux-gnu
-----
creating Makefile

current directory:
/home/smehsan/.rbenv/versions/2.4.7/lib/ruby/gems/2.4.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory:
/home/smehsan/.rbenv/versions/2.4.7/lib/ruby/gems/2.4.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
client.c: In function ‘nogvl_read_query_result’:
client.c:439:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
  439 |   my_bool res = mysql_read_query_result(client);
      |   ^~~~~~~
      |   bool
client.c: In function ‘_mysql_client_options’:
client.c:762:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
  762 |   my_bool boolval;
      |   ^~~~~~~
      |   bool
client.c:797:10: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean
‘MYSQL_DEFAULT_AUTH’?
  797 |     case MYSQL_SECURE_AUTH:
      |          ^~~~~~~~~~~~~~~~~
      |          MYSQL_DEFAULT_AUTH
client.c:797:10: note: each undeclared identifier is reported only once for each function it appears
in
client.c: In function ‘set_secure_auth’:
client.c:1185:38: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean
‘MYSQL_DEFAULT_AUTH’?
 1185 |   return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
      |                                      ^~~~~~~~~~~~~~~~~
      |                                      MYSQL_DEFAULT_AUTH
client.c:1186:1: warning: control reaches end of non-void function [-Wreturn-type]
 1186 | }
      | ^
client.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
make: *** [Makefile:243: client.o] Error 1

make failed, exit code 2

Gem files will remain installed in
/home/smehsan/.rbenv/versions/2.4.7/lib/ruby/gems/2.4.0/gems/mysql2-0.3.21 for inspection.
Results logged to
/home/smehsan/.rbenv/versions/2.4.7/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0/mysql2-0.3.21/gem_make.out

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'` succeeds before
bundling.

In Gemfile:
  mysql2

Can anyone please help me.

Thank you

Thank you All I have got the solution. This command help me to get out of it.

gem install mysql2 -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"

Thank to Reinmiedl

Thank you

2 Likes