Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix with --with-mysql-dir or --with-mysql-lib or --with-mysql-include #1118

Open
glouton opened this issue Apr 10, 2020 · 5 comments
Open

Fix with --with-mysql-dir or --with-mysql-lib or --with-mysql-include #1118

glouton opened this issue Apr 10, 2020 · 5 comments

Comments

@glouton
Copy link

glouton commented Apr 10, 2020

Hi there,

As per @sodabrew recommendation I'm opening a new issue.

I'm facing some error as in issue #952 with mysql2-0.5.3 when trying to install Redmine on CentOS 8.

I first installed it using
$ gem install mysql2 -- --with-mysql-dir=/usr

Then uninstalled the gem and tried to set some options in the bundle config
$ bundle config set build.mysql2 --with-mysql-lib=/usr/lib64/mysql --with-mysql-include=/usr/include/mysql
$ bundle install

In both cases the installation of mysql2 went well but then this error occur
$ bundle exec rake generate_secret_token ruby /home/redmine/.rvm/gems/ruby-2.6.5/bin/rake generate_secret_token: symbol lookup error: /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/lib/mysql2/mysql2.so: undefined symbol: mysql_server_init
$ bundle exec rake db:migrate RAILS_ENV=production ruby /home/redmine/.rvm/gems/ruby-2.6.5/bin/rake db:migrate RAILS_ENV=production: symbol lookup error: /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/lib/mysql2/mysql2.so: undefined symbol: mysql_server_init

If I follow the link above it seems to say that the fix has been merged since 0.5.2 but I have 0.5.3.

Please note that I'm using MariaDB server installed with their repository.

$ ldd /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/lib/mysql2/mysql2.so
linux-vdso.so.1 (0x00007ffd48794000)
libruby.so.2.6 => /home/redmine/.rvm/rubies/ruby-2.6.5/lib/libruby.so.2.6 (0x00007fbb55af5000)
libm.so.6 => /lib64/libm.so.6 (0x00007fbb55773000)
libc.so.6 => /lib64/libc.so.6 (0x00007fbb553b0000)
libz.so.1 => /lib64/libz.so.1 (0x00007fbb55199000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbb54f79000)
librt.so.1 => /lib64/librt.so.1 (0x00007fbb54d70000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fbb54b6c000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fbb54943000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbb56266000)

@sodabrew said:

I don't follow why you're using any config options at all. Your libraries are in a standard location. The build auto-detects standard locations by default.

I don't understand neither but if i try a regular "bundle install" or "gem install" it does not work.

$ bundle install
Fetching mysql2 0.5.3
Installing mysql2 0.5.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.
$ gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

    current directory: /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
/home/redmine/.rvm/rubies/ruby-2.6.5/bin/ruby -I /home/redmine/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0 -r ./siteconf20200410-24605-j24cg1.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... no
checking for MYSQL.net.pvio in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... yes
-----
Setting libpath to /usr/lib64/
-----
creating Makefile

current directory: /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean

current directory: /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
In file included from ./mysql2_ext.h:39,
                 from client.c:1:
client.c: Dans la fonction « rb_set_ssl_mode_option »:
./client.h:22:3: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^~~~~~~~~~~~~~~~~~~~
client.c:114:3: note: dans l'expansion de la macro « GET_CLIENT »
   GET_CLIENT(self);
   ^~~~~~~~~~
client.c:115:3: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
   int val = NUM2INT( setting );
   ^~~
client.c: Au plus haut niveau:
cc1: warning: option « -Wno-self-assign » non reconnue sur la ligne de commande
cc1: warning: option « -Wno-parentheses-equality » non reconnue sur la ligne de commande
cc1: warning: option « -Wno-constant-logical-operand » non reconnue sur la ligne de commande
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
statement.c: Dans la fonction « rb_raise_mysql2_stmt_error »:
statement.c:48:3: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
   VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt_wrapper->stmt));
   ^~~~~
statement.c:54:3: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
   rb_encoding *default_internal_enc = rb_default_internal_encoding();
   ^~~~~~~~~~~
In file included from ./mysql2_ext.h:39,
                 from statement.c:1:
statement.c: Dans la fonction « rb_mysql_stmt_execute »:
./client.h:22:3: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^~~~~~~~~~~~~~~~~~~~
statement.c:262:3: note: dans l'expansion de la macro « GET_CLIENT »
   GET_CLIENT(stmt_wrapper->client);
   ^~~~~~~~~~
statement.c:390:13: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
             VALUE rb_val_as_string = rb_funcall(argv[i], intern_to_s, 0);
             ^~~~~
In file included from ./mysql2_ext.h:39,
                 from statement.c:1:
statement.c: Dans la fonction « rb_mysql_stmt_fields »:
./client.h:22:3: warning: le C90 ISO interdit les mélanges de déclarations et de code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^~~~~~~~~~~~~~~~~~~~
statement.c:492:3: note: dans l'expansion de la macro « GET_CLIENT »
   GET_CLIENT(stmt_wrapper->client);
   ^~~~~~~~~~
statement.c: Au plus haut niveau:
cc1: warning: option « -Wno-self-assign » non reconnue sur la ligne de commande
cc1: warning: option « -Wno-parentheses-equality » non reconnue sur la ligne de commande
cc1: warning: option « -Wno-constant-logical-operand » non reconnue sur la ligne de commande
linking shared-object mysql2/mysql2.so
/usr/bin/ld : ne peut trouver -lmariadb
collect2: error: ld a retourné le statut de sortie 1
make: *** [Makefile:262: mysql2.so] Error 1

make failed, exit code 2

Gem files will remain installed in /home/redmine/.rvm/gems/ruby-2.6.5/gems/mysql2-0.5.3 for inspection.
Results logged to /home/redmine/.rvm/gems/ruby-2.6.5/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/gem_make.out

Regards,

@glouton
Copy link
Author

glouton commented Apr 10, 2020

Hello,

Managed to install without passing any options.
I installed MariaDB-devel but was missing MariaDB-shared which is needed apparently.

Regards,

@sodabrew
Copy link
Collaborator

Thanks for opening a new issue. And, in fact have you resolved the problem? Can the issue be closed at this time, or is there some improvement you'd like to see in the msyql2 gem or documentation?

(open-and-shut tickets like these are actually very helpful for the next person who has a similar problem to find the resolution, thank you very much for posting your follow-up message!)

@glouton
Copy link
Author

glouton commented Apr 11, 2020

Hi,

Thank you for answering me so quiclky twice.
Your first answer in the original ticket actually made me realised I was maybe missing a dependency and dig a little deeper.

As a result there's two distinct things going on here and I'm not sure if we can close the ticket.

  1. It might be worth mentioning in the documentation that MariaDB-shared is needed and not only MariaDB-devel
  2. Without MariaDB-shared I could install mysql2 only by passing options to set dir or lib path and in this case the library wasn't linked and commands like "bundle exec rake..." were failing because of "undefined symbol: mysql_server_init"

I give you that it's a very twisted case as everything works fine out of the box with all the right dependencies installed (i.e.: including MariaDB-shared). And maybe point 2 happends only in this twisted situation.

Anyway, as far as I'm concern all is good, redmine is installed up and running.

Thank you again and glad if this can help anyone in the future.

Regards,
Charles

@hectorcorrea
Copy link

hectorcorrea commented Jul 22, 2020

I am getting the same error. I can compile the gem by passing the --with-mysql-dir parameter to use a newer version of the MySQL client libraries than the default version on the server:

$ gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/' -- --with-mysql-dir=/opt/rh/rh-mysql57/root/usr
Fetching mysql2-0.5.3.gem
Building native extensions with: '--with-mysql-dir=/opt/rh/rh-mysql57/root/usr'
This could take a while...
Successfully installed mysql2-0.5.3
Parsing documentation for mysql2-0.5.3
Installing ri documentation for mysql2-0.5.3
Done installing documentation for mysql2 after 0 seconds
1 gem installed

But then the gem throws an error when I try to use it:

$ ruby -rmysql2 -e 'puts 123' 
ruby: symbol lookup error: /opt/local/.gem/ruby/2.7.1/gems/mysql2-0.5.3/lib/mysql2/mysql2.so: undefined symbol: mysql_server_init

In my case the server has an old version of MySQL running that we cannot remove because it is used by other apps. We installed the MySQL client libraries for a newer version of MySQL so that we can connect to another database server and compiled against this newer libraries but the mysql2 gem throws the "undefined symbol: mysql_server_init" when it is loaded.

For what is worth, this is with Ruby 2.7.1 and Red Hat 6

$ ruby --version
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.10 (Santiago)

@hectorcorrea
Copy link

hectorcorrea commented Jul 23, 2020

Our sys admin was able to workaround this issue by using both the with-mysql-dir and the with-mysql-lib parameters when installing the gem and pointing them to mariadb55 (instead of mysql57).

Make sure the "devel" package is installed on the server, otherwise it won't find the include files that it needs to build the gem.

$ yum list installed | grep maria
mariadb55.x86_64             1.1-17.el6            @rhel-server-rhscl-6-rpms    
mariadb55-mariadb.x86_64     5.5.53-1.el6          @rhel-server-rhscl-6-rpms    
mariadb55-mariadb-devel.x86_64
mariadb55-mariadb-libs.x86_64
mariadb55-mariadb-server.x86_64
mariadb55-runtime.x86_64     1.1-17.el6            @rhel-server-rhscl-6-rpms  
$ scl enable mariadb55 bash

$ gem install mysql2 -- --with-mysql-dir=/opt/rh/mariadb55/root/usr --with-mysql-lib=/usr/lib64/mysql
Building native extensions with: '--with-mysql-dir=/opt/rh/mariadb55/root/usr --with-mysql-lib=/usr/lib64/mysql'
This could take a while...
Successfully installed mysql2-0.5.3
Parsing documentation for mysql2-0.5.3
Installing ri documentation for mysql2-0.5.3
Done installing documentation for mysql2 after 0 seconds
1 gem installed

$ ruby -rmysql2 -e 'puts 123'
123

I believe the symbol mysql_server_init is defined in the libmysqlclient.so file which exists in the /usr/lib64/mysql and hence the need to use that extra parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants