mysql2: `ld: library not found for -lssl` after Mac OS Sierra upgrade

After upgrading to Sierra. Confirmed that OpenSSL and LibreSSL are installed through Homebrew. I’m continuing to troubleshoot.

gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    /Users/frank/.rbenv/versions/2.2.4/bin/ruby -r ./siteconf20161017-40878-1pj8mbn.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/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mariadb/10.1.18/lib
-----
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/frank/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/mysql2-0.4.4 for inspection.
Results logged to /Users/frank/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-16/2.2.0-static/mysql2-0.4.4/gem_make.out

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 22
  • Comments: 70 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Step 1.

brew install openssl

Step 2.

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

Changing the $LIBRARY_PATH did not work for me, but this did:

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

The solution was: xcode-select --install

I really wish XCode would update without removing the command line tools every time without notice.

To fix for a manual gem install:

brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"

To fix for all bundle installs:

brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install

Step 1.

brew install openssl

Step 2.

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

Thank you @dibowei I will never get those couple of hours back but you definitely saved me a few more!

Step 1.

brew install openssl

Step 2.

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

Thank you very much @dibowei, same thing happened in OS X 10.14 Mojave, this fixed it.

This error occurred for me trying to install mysql2 gem with gem install mysql2

(posting this so hopefully future poor souls googling mysql2 install errors will see this…)

Hm this didn’t work for me still seeing same error

You can also try this on macOS

  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

Step 1.

brew install openssl

Step 2.

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

This thread ranks highly in Google. For other people arriving here after trying to get mysql2 gem going on OS X 10.14 Mojave, this did it for me. Stuck it in .bash_profile as well.

I had problem installing psycopg2 with error message

ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1

on macos Big Sur devBeta 2, xcode 12 Beta and command line tools all installed.

Step 1. brew install openssl Step 2. export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

thank you bro!!!

solved the problem right away.

I encountered this error when using pip install MySQL-python. Commenting here as the above solution worked (again for googlers)

If you’re using openssl installed by homebrew natively on Apple Silicon, openssl@1.1/lib no longer lives at /usr/local/opt. For an architecture independent way of referring to openssl, try:

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix openssl@1.1)/lib/

Step 1.

brew install openssl

Step 2.

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

This saved me hours, Thanks ^_^

Step 1.

brew install openssl

Step 2.

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

I love you

I have command line tools installed as well as Xcode 9. I tried reinstalling command line tools by mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools.bak and running xcode-select --install again. I also tried a restart as suggested above, with no luck. Is there a way to tell it where openssl is installed?

$ gem install mysql2 -v '0.4.8'
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

    current directory: /Users/mastahyeti/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.8/ext/mysql2
/Users/mastahyeti/.rbenv/versions/2.3.3/bin/ruby -r ./siteconf20170808-1961-j6vuqi.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
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
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql@5.6/5.6.34/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/mastahyeti/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.8/mkmf.log

current directory: /Users/mastahyeti/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.8/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/mastahyeti/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.8/ext/mysql2
make "DESTDIR="
compiling infile.c
compiling client.c
compiling mysql2_ext.c
compiling statement.c
compiling result.c
result.c:326:40: warning: incompatible pointer types assigning to 'my_bool *' (aka 'char *') from 'bool *' [-Wincompatible-pointer-types]
    wrapper->result_buffers[i].is_null = &wrapper->is_null[i];
                                       ^ ~~~~~~~~~~~~~~~~~~~~
result.c:328:40: warning: incompatible pointer types assigning to 'my_bool *' (aka 'char *') from 'bool *' [-Wincompatible-pointer-types]
    wrapper->result_buffers[i].error   = &wrapper->error[i];
                                       ^ ~~~~~~~~~~~~~~~~~~
2 warnings generated.
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/mastahyeti/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.8 for inspection.
Results logged to /Users/mastahyeti/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.8/gem_make.out
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Update: I got it working after doing rbenv local 2.4.0. Not sure why this worked.

MacOS Monterey

Check your installed mysql version(i’m using 8.0.28_1) ls /opt/homebrew/Cellar/mysql

Change the bundle.mysql2 config (change ‘8.0.28_1’ for the mysql installed version)

bundle config build.mysql2 -- \ --with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28_1/lib \ --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1 \ --with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28_1/bin/mysql_config \ --with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28_1/include

Run: bundle install

Step 1.

brew install openssl

Step 2.

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

@dibowei Thanks for the fix. It worked like a charm. I can’t believe 2 years later and this this still needs to be done by hand.

hit this on catalina with xcode 11.2 and had to make a slight tweak on previous solutions to use openssl@1.1

bundle config build.mysql2 --with-opt-dir=“$(brew --prefix openssl@1.1)”

The solution was: xcode-select --install

I really wish XCode would update without removing the command line tools every time without notice.

when i run xcode-select --install i get error xcode-select: error: command line tools are already installed, use “Software Update” to install updates

exactly same error as @mastahyeti

Even after making a:

brew install openssl@1.1    

Step 1.

brew install openssl

Step 2.

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

@dibowei’s solution worked but with modified for Apple M1 export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/Cellar/openssl@1.1/1.1.1k/lib

Step 1.

brew install openssl

Step 2.

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

Thanks soooooo much 👍

Step 1. brew install openssl Step 2. export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

This thread ranks highly in Google. For other people arriving here after trying to get mysql2 gem going on OS X 10.14 Mojave, this did it for me. Stuck it in .bash_profile as well.

This also worked for Python’s mysqlclient:

LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient

Oh, glad you found it. Yeah, that’s annoying every time. Maybe a specific check is in order? I wonder if xcode-select --print-path fails after an upgrade.

Thanks @profx, your tips solved similar for me on Mojave 🎉

Had to do the below after a xcode-select --install

cd  /Library/Developer/CommandLineTools/Packages/ && open macOS_SDK_headers_for_macOS_10.14.pkg
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip install psycopg2

_From https://stackoverflow.com/a/56228387/946175 and https://stackoverflow.com/a/55732339/946175_

Step 1.

brew install openssl

Step 2.

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

This saved my day!

if anyone is facing issue while installing mysqlclient in mac. Use this command.

LDFLAGS=-L/usr/local/opt/openssl/lib pip3 install mysqlclient

No luck tried all the above, below are the details:

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

    current directory: /Users/codemilan/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.1/ext/mysql2
/Users/codemilan/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20190618-4368-cptjrt.rb extconf.rb --with-opt-dir=/usr/local/opt/openssl
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/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting rpath to /usr/local/Cellar/mysql/8.0.16/lib
-----
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/codemilan/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-18/2.4.0-static/mysql2-0.4.1/mkmf.log

current directory: /Users/codemilan/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.1/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/codemilan/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.1/ext/mysql2
make "DESTDIR="
compiling client.c
In file included from client.c:1:
In file included from ./mysql2_ext.h:10:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby.h:33:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:24:
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:15:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define __EXTENSIONS__ 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:16:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define _ALL_SOURCE 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:17:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define _GNU_SOURCE 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:18:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define _POSIX_PTHREAD_SEMANTICS 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:19:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define _TANDEM_SOURCE 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:316:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define __STDC_WANT_LIB_EXT1__ 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:350:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define _REENTRANT 1
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/x86_64-darwin18/ruby/config.h:351:9: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#define _THREAD_SAFE 1
        ^
In file included from client.c:1:
In file included from ./mysql2_ext.h:10:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby.h:33:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:36:
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/defines.h:163:8: warning: macro name is a reserved identifier [-Wreserved-id-macro]
#undef __
       ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/defines.h:165:10: warning: macro name is a reserved identifier [-Wreserved-id-macro]
# define __(args) args
         ^
In file included from client.c:1:
In file included from ./mysql2_ext.h:10:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby.h:33:
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:840:5: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type
('int') and becomes negative [-Wshift-sign-overflow]
    RUBY_FL_USER_N(19),
    ^~~~~~~~~~~~~~~~~~
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:819:47: note: expanded from macro 'RUBY_FL_USER_N'
#define RUBY_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n))
                                             ~^ ~~~~~~~~~~~~~~~~~~
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1695:53: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
                                                    ^
                                                            void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1695:70: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
                                                                     ^
                                                                             void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1696:59: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
                                                          ^
                                                                  void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1696:76: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
                                                                           ^
                                                                                   void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1702:49: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int);
                                                ^
                                                        void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1703:58: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int);
                                                         ^
                                                                 void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1704:52: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int);
                                                   ^
                                                           void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1830:38: warning: this function declaration is not a prototype [-Wstrict-prototypes]
typedef VALUE (*rb_block_call_func_t)(ANYARGS);
                                     ^
                                             void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1841:48: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
                                               ^
                                                       void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1843:25: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
                        ^
                                void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1843:49: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
                                                ^
                                                        void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1844:26: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
                         ^
                                 void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1844:50: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
                                                 ^
                                                         void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1845:25: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
                        ^
                                void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1845:49: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
                                                ^
                                                        void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1846:36: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
                                   ^
                                           void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1847:34: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE);
                                 ^
                                         void
In file included from client.c:1:
In file included from ./mysql2_ext.h:10:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby.h:33:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:2001:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:35:
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/st.h:62:19: warning: this function declaration is not a prototype [-Wstrict-prototypes]
    int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
                  ^
                                                   void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/st.h:63:23: warning: this function declaration is not a prototype [-Wstrict-prototypes]
    st_index_t (*hash)(ANYARGS /*st_data_t*/);        /* st_hash_func* */
                      ^
                                            void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/st.h:121:35: warning: this function declaration is not a prototype [-Wstrict-prototypes]
int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
                                  ^
                                          void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/st.h:122:41: warning: this function declaration is not a prototype [-Wstrict-prototypes]
int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t);
                                        ^
                                                void
In file included from client.c:1:
In file included from ./mysql2_ext.h:10:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby.h:33:
In file included from /Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:2001:
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:207:46: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int);
                                             ^
                                                     void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:210:62: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
                                                             ^
                                                                     void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:211:60: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
                                                           ^
                                                                   void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:212:61: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int);
                                                            ^
                                                                    void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:218:29: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_fiber_new(VALUE (*)(ANYARGS), VALUE);
                            ^
                                    void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:426:28: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
                           ^
                                                                        void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:455:33: warning: this function declaration is not a prototype [-Wstrict-prototypes]
VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
                                ^
                                        void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:507:48: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t);
                                               ^
                                                       void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:509:36: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE);
                                   ^
                                           void
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/intern.h:941:36: warning: this function declaration is not a prototype [-Wstrict-prototypes]
void rb_ivar_foreach(VALUE, int (*)(ANYARGS), st_data_t);
                                   ^
                                           void
In file included from client.c:1:
In file included from ./mysql2_ext.h:41:
./result.h:24:3: error: unknown type name 'my_bool'
  my_bool *is_null;
  ^
./result.h:25:3: error: unknown type name 'my_bool'
  my_bool *error;
  ^
client.c:260:9: warning: use of GNU statement expression extension [-Wgnu-statement-expression]
  obj = Data_Make_Struct(klass, mysql_client_wrapper, rb_mysql_client_mark, rb_mysql_client_free, wrapper);
        ^
/Users/codemilan/.rbenv/versions/2.4.0/include/ruby-2.4.0/ruby/ruby.h:1155:54: note: expanded from macro 'Data_Make_Struct'
#define Data_Make_Struct(klass,type,mark,free,sval) ({\
                                                     ^
client.c:434:3: error: use of undeclared identifier 'my_bool'
  my_bool res = mysql_read_query_result(client);
  ^
client.c:436:19: error: use of undeclared identifier 'res'
  return (void *)(res == 0 ? Qtrue : Qfalse);
                  ^
client.c:759:3: error: use of undeclared identifier 'my_bool'
  my_bool boolval;
  ^
client.c:790:7: error: use of undeclared identifier 'boolval'
      boolval = (value == Qfalse ? 0 : 1);
      ^
client.c:791:17: error: use of undeclared identifier 'boolval'
      retval = &boolval;
                ^
client.c:794: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.16/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
client.c:795:7: error: use of undeclared identifier 'boolval'
      boolval = (value == Qfalse ? 0 : 1);
      ^
client.c:796:17: error: use of undeclared identifier 'boolval'
      retval = &boolval;
                ^
client.c:827:38: error: use of undeclared identifier 'boolval'
        wrapper->reconnect_enabled = boolval;
                                     ^
client.c:1182:38: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
  return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
                                     ^~~~~~~~~~~~~~~~~
                                     MYSQL_DEFAULT_AUTH
/usr/local/Cellar/mysql/8.0.16/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
43 warnings and 12 errors generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/codemilan/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.1 for inspection.
Results logged to /Users/codemilan/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-18/2.4.0-static/mysql2-0.4.1/gem_make.out

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

Mojave 10.14.3

Step 1.

brew install openssl

Step 2.

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

Might be for someone brew reinstall openssl . After like 12 hours of searching worked for me.

when i run xcode-select --install i get error xcode-select: error: command line tools are already installed, use “Software Update” to install updates

Same for me on Mojave, but this solution https://github.com/brianmario/mysql2/issues/795#issuecomment-433219176 worked fine

In my case, I was having trouble installing MySQL-python on python 2.7 with openssl@1.1. Taking cues from the above, I realized that the symlinks were not being passed properly. So I proceeded to link openssl manually

brew link openssl

This failed with a denied error, but prompted me the right steps

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

I then passed the correct linker flags and it worked (later updated my bashrc)

sudo env LDFLAGS="-I/usr/local/opt/openssl@1.1/include -L/usr/local/opt/openssl@1.1/lib" pip install MySQL-python

image

Later, set the flags in your bash profiles. God damn, clang/openssl on Mac.

I faced the same issue in MAC OS Catalina. A slight variation of the above solutions/workarounds helped me solve the issue: Step 1: brew install openssl (this installs openssl@1.1) Step 2: export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl\@1.1/lib/

I encountered this error while installing psycopg2 on Mojave into a virtual Python environment created with pyenv. I already had Xcode and the Command Line Tools installed, and checked that using the xcode-select --install command, xcode-select -p, and echo $?, which returned a 0, indicating they were installed.

It turns out Mojave and/or Xcode 10 does not create a /usr/include directory, which psycopg2 needs to install (other “legacy” apps may need this, too, as indicated in Apple’s developer forum. I posted about it here https://stackoverflow.com/questions/26288042/error-installing-psycopg2-library-not-found-for-lssl/57746760#5774676, but found the solution here: https://stackoverflow.com/questions/34617452/how-to-update-xcode-from-command-line, which references https://forums.developer.apple.com/thread/104296.

Step 1.

brew install openssl

Step 2.

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

A combination of this and running pip install MySQL-python seperately instead of pip install -r requirements.txt worked for me 🙏

Step 1.

brew install openssl

Step 2.

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

works for me on Mojave 😉 many thanks

I had upgraded from Sierra to High Sierra a couple of weeks back. I received this error when I tried to install mysqlclient. After running xcode-select --install the problem disappeared. Thank you!

Step 1.

brew install openssl

Step 2.

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

This worked for me. Thanks!

This solution deserves its own documentation repo, with different fixes for the platforms, along with PRs to fix them! 😄

Step 1.

brew install openssl

Step 2.

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

Also helped me, many thanks!

I didn’t realize brew was so buggy. I brew installed plantuml and suddenly couldn’t get my existing rails application to work. I did bundle pristine --all as mentioned https://stackoverflow.com/a/59438200, and it showed a mysql2 error, which led me here. It also broke vim:

$ vim
dyld: Library not loaded: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python
  Referenced from: /usr/local/bin/vim
  Reason: image not found
Abort trap: 6

Versions: MacOS 10.14.6 gem install mysql2 -v ‘0.4.10’

The solution was: xcode-select --install

I really wish XCode would update without removing the command line tools every time without notice.

Thanks @rietta, still works in 2020. Kudos 👍

Try:

$ brew uninstall --ignore-dependencies --force openssl
$ brew install openssl

$ brew uninstall --ignore-dependencies --force readline
$ brew install readline

Step 1.

brew install openssl

Step 2.

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

Happy to report @dibowei that even almost two years later, this suggestion helped! Particularly Step 2. Thanks

Step 1.

brew install openssl

Step 2.

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

This works for me!

Step 1.

brew install openssl

Step 2.

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

Thanks @dibowei, that worked!

Posting this comment just to share my experience and help other people. I fixed this error by uninstalling and installing mysql formula from homebrew, I suspect the error was originated by updating to macOS Mojave. My old mysql version was 5.7.22 and after reinstalling mysql it was 8.0.13, so had to install an older version mysql@5.7 and then brew link.

I had this error while trying to install the MySQL-python connector. Running xcode-select --install solved that immediately.

Thanks a lot for the info