简体   繁体   中英

An error occurred while installing mysql (2.9.1), and Bundler cannot continue

I am getting two errors with stack traces before this. Those are:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': 

 The compiler failed to generate an executable file. (RuntimeError). 
 You have to install development tools first.

    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:782:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1069:in `block in have_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1068:in `have_func'

and

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200218-95654-zjppya.rb extconf.rb
checking for mysql_ssl_set()... *** 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.

This is the main error: Or what bundler tells me:

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

I have done a ton of research all over.

Solution 1 (Installing the correct developer tools):

Install xcode and xcode developer tools, run command:

xcode-select --install

I get :

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

The project I'm working on requires ruby version 1.9.3.

I'm just really lost on what to do because I don't know what headers are and have entered a lot of commands through bundler and reseting xcode as well as deleting the tools and reinstalling. When I use bundle clean --force I get:

Could not find mysql-2.9.1 in any of the sources

What should I do? I've looked at others that relate to this but the commands don't fix it and I don't anything about mysql 2.9.1 exactly.

EDIT: I should have posted this in since it requested me to make sure it worked:

mysql-2.9.1 git:(testupdategem) ✗ sudo gem install mysql -v '2.9.1'
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

        /Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/bin/ruby extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile

make
compiling mysql.c
mysql.c:79:2: error: unknown type name 'my_bool'
        my_bool *is_null;
        ^
mysql.c:361:5: error: use of undeclared identifier 'my_bool'
    my_bool b;
    ^
mysql.c:391:10: error: use of undeclared identifier 'MYSQL_SET_CLIENT_IP'; did you mean 'MYSQL_SET_CHARSET_DIR'?
    case MYSQL_SET_CLIENT_IP:
         ^~~~~~~~~~~~~~~~~~~
         MYSQL_SET_CHARSET_DIR
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:176:3: note: 'MYSQL_SET_CHARSET_DIR' declared here
  MYSQL_SET_CHARSET_DIR,
  ^
mysql.c:398:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
    case MYSQL_SECURE_AUTH:
         ^~~~~~~~~~~~~~~~~
         MYSQL_DEFAULT_AUTH
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:187:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
mysql.c:400:6: error: use of undeclared identifier 'b'
            b = 1;
            ^
mysql.c:402:6: error: use of undeclared identifier 'b'
            b = 0;
            ^
mysql.c:403:14: error: use of undeclared identifier 'b'
        v = (char*)&b;
                    ^
mysql.c:391:10: error: duplicate case value 'MYSQL_SET_CHARSET_DIR'
    case MYSQL_SET_CLIENT_IP:
         ^
mysql.c:384:10: note: previous case defined here
    case MYSQL_SET_CHARSET_DIR:
         ^
mysql.c:588:9: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Wshorten-64-to-32]
    n = mysql_num_rows(res);
      ~ ^~~~~~~~~~~~~~~~~~~
mysql.c:633:9: warning: implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'unsigned int' [-Wshorten-64-to-32]
    n = mysql_num_rows(res);
      ~ ^~~~~~~~~~~~~~~~~~~
mysql.c:878:5: error: use of undeclared identifier 'my_bool'
    my_bool true = 1;
    ^
mysql.c:883:61: error: cannot take the address of an rvalue of type 'int'
    if (mysql_stmt_attr_set(s, STMT_ATTR_UPDATE_MAX_LENGTH, &true))
                                                            ^~~~~
mysql.c:1068:73: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                int len = strlen(fields[i].table)+strlen(fields[i].name)+1;
                    ~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
mysql.c:1661:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
    n = mysql_stmt_param_count(s->stmt);
      ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mysql.c:2049:52: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
    rb_define_const(cMysql, "SECURE_AUTH", INT2NUM(MYSQL_SECURE_AUTH));
                                                   ^~~~~~~~~~~~~~~~~
                                                   MYSQL_DEFAULT_AUTH
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:973:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:187:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
mysql.c:2050:61: error: use of undeclared identifier 'MYSQL_OPT_GUESS_CONNECTION'; did you mean 'MYSQL_OPT_RECONNECT'?
    rb_define_const(cMysql, "OPT_GUESS_CONNECTION", INT2NUM(MYSQL_OPT_GUESS_CONNECTION));
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
                                                            MYSQL_OPT_RECONNECT
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:973:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:185:3: note: 'MYSQL_OPT_RECONNECT' declared here
  MYSQL_OPT_RECONNECT,
  ^
mysql.c:2051:68: error: use of undeclared identifier 'MYSQL_OPT_USE_EMBEDDED_CONNECTION'
    rb_define_const(cMysql, "OPT_USE_EMBEDDED_CONNECTION", INT2NUM(MYSQL_OPT_USE_EMBEDDED_CONNECTION));
                                                                   ^
mysql.c:2052:66: error: use of undeclared identifier 'MYSQL_OPT_USE_REMOTE_CONNECTION'
    rb_define_const(cMysql, "OPT_USE_REMOTE_CONNECTION", INT2NUM(MYSQL_OPT_USE_REMOTE_CONNECTION));
                                                                 ^
mysql.c:2053:54: error: use of undeclared identifier 'MYSQL_SET_CLIENT_IP'; did you mean 'MYSQL_SET_CHARSET_DIR'?
    rb_define_const(cMysql, "SET_CLIENT_IP", INT2NUM(MYSQL_SET_CLIENT_IP));
                                                     ^~~~~~~~~~~~~~~~~~~
                                                     MYSQL_SET_CHARSET_DIR
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:973:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/include/ruby-1.9.1/ruby/ruby.h:225:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
/usr/local/Cellar/mysql/8.0.19/include/mysql/mysql.h:176:3: note: 'MYSQL_SET_CHARSET_DIR' declared here
  MYSQL_SET_CHARSET_DIR,
  ^
In file included from mysql.c:2287:
./error_const.h:2608:27: error: use of undeclared identifier 'ER_XPLUGIN_IP'
    rb_define_mysql_const(ER_XPLUGIN_IP);
                          ^
4 warnings and 16 errors generated.
make: *** [mysql.o] Error 1


Gem files will remain installed in /Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/gems/1.9.1/gems/mysql-2.9.1 for inspection.
Results logged to /Users/tblevins/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/gems/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out

Instructions: Install RVM with \\curl -sSL https://get.rvm.io | bash -s stable \\curl -sSL https://get.rvm.io | bash -s stable ; restart your shell; install Ruby with rvm install 1.9.3.

 Error running 'env GEM_HOME=/Users/tblevins/.rvm/gems/ruby-1.9.3- 
 p551@global GEM_PATH= /Users/tblevins/.rvm/rubies/ruby-1.9.3- 
 p551/bin/ruby -d /Users/tblevins/.rvm/src/rubygems-3.0.7/setup.rb -- 
 no-document', please read /Users/tblevins/.rvm/log/1582058102_ruby- 
 1.9.3-p551/rubygems.install.log 

Says this is rubygems.install.log file:

 Exception LoadError' at /Users/tblevins/.rvm/rubies/ruby-1.9.3- 
 p551/lib/ruby/1.9.1/rubygems.rb:1264 - cannot load such file -- 
 rubygems/defaults/operating_system Exception LoadError' at /. 
 Users/tblevins/.rvm/rubies/ruby-1.9.3- 
 p551/lib/ruby/1.9.1/rubygems.rb:1273 - cannot load such file -- 
 rubygems/defaults/ruby. AND /Users/tblevins/.rvm/src/rubygems- 
 3.0.7/lib/rubygems/core_ext/kernel_warn.rb:18: void value expression 
 /Users/tblevins/.rvm/src/rubygems- 
 3.0.7/lib/rubygems/core_ext/kernel_warn.rb:43: syntax error, 
 unexpected '}', expecting keyword_end 

For future viewers: I had to do:

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

I also had to clean up my brew and link git/node. It was a lot of try and fail, I'm sorry I don't remember all of it.

Also I did:

bundle config --local build.mysql “--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Bundler Version 1.16.4 Ruby version 1.9.3-p551

Welcome to Stack Overflow.

Before I answer your question, I'd recommend anothermh's advice . I've been using rbenv because I work on a team of other people that do, but rvm is great. Don't use the system installation of Ruby. If you stick with Ruby development, you will be glad you did.

That said, setting up a non-system ruby environment won't be enough to fix this problem. First, the mysql gem version you're looking at is old, I think from 2013. It depends on a version of openssl that is no longer supported and has multiple security vulnerabilities. Please don't use it.

If you can, switch to using the mysql2 gem. For most Ruby and Rails projects, the mysql2 gem is pretty close to a drop-in replacement. If latest version of the mysql2 gem still doesn't compile on your machine, please see this previous question for answers on how to fix it.

It's possible that you're in the sad position where the mysql2 gem upgrade is not a option for you. If that's the case, you'll need to find a 1.0.x version of the OpenSSL library. Install the old version of OpenSSL on your machine to some path — let's call that path <openssl_path> for now. Then you can pass that path as an argument to bundler config or you can install the gem directly like so:

gem install mysql -v '2.9.1' -- --with-cflags=\\"-I<openssl_path>/include\\" --with-ldflags=\\"-L<openssl_path>/lib\\"

This still leaves you with the problem of finding OpenSSL 1.0, though. I know that several people previously posted ways to still install it via homebrew, though several of the repositories that hosted the required downloads for that to work are no longer active. Perhaps someone has posted another since last time I checked. I haven't been able to find one recently.

At worst, I suppose you could go to https://www.openssl.org/source/old/ and download an old version and compile it. Again, I recommend upgrading to the mysql2 gem instead as that might be a much easier path for you.

Here is what worked for me on OSX:

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

gem install mysql -v '2.9.1'

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM