11

After updating perl via homebrew, i broke my dbd::mysql installation installing via cpanm results in:

I will use the following settings for compiling and testing:

    cflags        (mysql_config) = -I/usr/local/Cellar/mysql-connector-
    c/6.1.9/include
    embedded      (guessed     ) =
    ldflags       (guessed     ) =
    libs          (mysql_config) = -L/usr/local/Cellar/mysql-connector-
    c/6.1.9/lib -l
    mysql_config  (guessed     ) = mysql_config
    nocatchstderr (default     ) = 0
    nofoundrows   (default     ) = 0
    nossl         (default     ) = 0
    testdb        (default     ) = test
    testhost      (default     ) =
    testpassword  (default     ) =
    testport      (default     ) =
    testsocket    (default     ) =
    testuser      (guessed     ) = root

To change these settings, see 'perl Makefile.PL --help' and 'perldoc DBD::mysql::INSTALL'.

Checking if libs are available for compiling...
Can't link/include C library '', aborting.

Does anyone know how to resolve? I've tried removing mysql-connector-c and installing mysql via homebrew instead. The complaint then is Can't link/include C library 'ssl', 'crypto', aborting. I do have openssl installed.

perl version:

This is perl 5, version 24, subversion 1 (v5.24.1) built for
darwin-thread-multi-2level
Bilal
  • 2,883
  • 5
  • 37
  • 60
dion
  • 121
  • 1
  • 3

5 Answers5

15

This is an old question, but I just had this problem installing DBD::mysql and I see that others are still having this problem too. Here's the convoluted solution that worked for me.

I started by running (MacOX Mojave 10.14.1):

  • brew install mysql
  • cpanm install DBD::mysql
  • This fails.

This gave me the error message "Can't link/include C library 'ssl', 'crypto', aborting". As per this thread and the DBD::mysql install instructions on meta-cpan, this error is happening because the DBD::mysql package requires (?) "mysql-connector-c" rather than "mysql". Okay, I fixed that by doing:

  • brew unlink mysql
  • brew install mysql-connector-c
  • cpanm install DBD::mysql
  • The cpan install still fails, but new error!

That "fixed" the issue in that it got me a different error message. I was now getting the message: "Can't link/include C library'', aborting". Progress! Now I was getting the error on this answer. I fixed this error by:

  • Verifying that my problem is indeed from missing linkage flags.
  • Run mysql_config
  • This returns something like: --libs [L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -l]
  • Note that the "-l" at the end has nothing after it, which is incorrect.
  • Edit /usr/local/Cellar/mysql-connector-c/6.1.11/bin/mysql_config line #114
  • Change libs="$libs -l" to libs="$libs -lmysqlclient"
  • Verify that it worked: mysql_config
  • This should return something like: --libs [L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient]
  • Again do cpanm install DBD::mysql
  • This time it works!!!
  • Be wary: We're not installing the lib for SSL connections which will probably cause cryptic problems later.

This got DBD::mysql installed successfully for me. I do think I'm going to have to go back and add some more linkage flags.

dtsong
  • 3
  • 2
charley
  • 198
  • 1
  • 10
  • 1
    What happens to the databases installed via `mysql` when you run `brew unlink mysql $$ brew install mysql-connector-c`?? I gave up because I don't wanna mess up my *AMP stack. – Yes Barry May 15 '19 at 02:03
  • 1
    I don't know, but caution seems wise. You should certainly [back up](http://osxdaily.com/2017/01/19/export-import-all-mysql-databases/) your DB somewhere if you care about whats in it. Also, dunno if this is useful, but this ended up being such a pain I switched to using Python for accessing MySQL. – charley May 16 '19 at 13:15
14
  1. show mysql_config path by which mysql_config

    eg: /usr/local/opt/mysql@5.7/bin/mysql_config

  2. show openssl lib path by which openssl. note: if it's a symbol in /usr/local/bin/openssl, you can type ls -ld /usr/local/bin/openssl to show real path

    eg: if it's /usr/local/openssl/bin/openssl, then you can insert -L/usr/local/openssl/lib/ for searching crypto and ssl libs

  3. edit mysql_config file and insert path of openssl lib(line #114)

    eg: libs=$libs -L/usr/local/opt/openssl/lib

    insert path of openssl lib 4.type cpan install DBD::mysql , success.

Homqyy
  • 141
  • 1
  • 6
  • 3
    This worked for me, with one tweak. I found the openssl lib path in the output from `brew info openssl` not `which openssl`, because Homebrew installs it as keg-only. – Matt Ryall Dec 11 '20 at 00:38
  • I've used this fix loads of times, and have now opened [an issue](https://github.com/Homebrew/homebrew-core/issues/72333) on homebrew-core that references this comment, so hopefully I'll never to use it again! – DrHyde Mar 02 '21 at 17:31
3

Stumbled upon this AGAIN, and after none of the answers worked, this one helped right away:

PATH="$(brew --prefix mysql-client)/bin:$PATH"
export LIBRARY_PATH=$(brew --prefix openssl)/lib:$LIBRARY_PATH
cpanm DBD::mysql

Credit goes to https://blog.mitsuto.com/macos-mojave-perl-dbd-mysql

Benny K
  • 1,107
  • 12
  • 9
3

I followed the link given in @Benny K answer as the commands he gave didn't worked for me and simply executed the below command and it worked

cpanm DBD::mysql --configure-args="--libs='-L/usr/local/opt/openssl/lib -lssl -lcrypto -L/usr/local/lib -lmysqlclient'"
Ram
  • 111
  • 1
  • 6
0

i got the same error and while poking around trying to figure it out I added -I/usr/local/mysql/include to the perl makefile.pl command. This didn't work but like a goat i tried again and then it came up with an Xcode agreement form that I had to read and abide by. Longer story i upgraded an older macbook pro to el capitan then had to install Xcode 6.3 last week. I'd forgotten about the newer Xcode. Anyway, the end result was a successful install once i'd agreed to the Xcode usage

  • thanks for the reply Mike, still no joy for me perl Makefile.PL --testuser=username cflags (mysql_config) = -I/usr/local/Cellar/mysql-connector-c/6.1.9/include embedded (guessed ) = ldflags (guessed ) = libs (mysql_config) = -L/usr/local/Cellar/mysql-connector-c/6.1.9/lib -l mysql_config (guessed ) = mysql_config nocatchstderr (default ) = 0 Checking if libs are available for compiling... Can't link/include C library '', aborting. – dion May 01 '17 at 13:22