1

I'm trying to install mysqlclient on MacOS from requirements.txt of a Python(3.8) project. I created a virtual environment and this is the output while trying to install it:

ld: library not found for -lzlib  
clang: error: linker command failed with exit code 1 (use -v to see invocation)  
error: command '/usr/bin/gcc' failed with exit code 1  
[end of output]

Note that lzlib is already installed. I read that MacOS has clang for compilation of C libraries and I installed gcc using Homebrew. Still the default clang was being picked up as is evident from the following output:

$ gcc -v  
Apple clang version 14.0.3 (clang-1403.0.22.14.1)  
Target: x86_64-apple-darwin22.4.0  
Thread model: posix  
InstalledDir: /Library/Developer/CommandLineTools/usr/bin 



$ gcc-13 -v  
Using built-in specs.  
COLLECT_GCC=gcc-13  
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-apple-darwin22/13/lto-wrapper  
Target: x86_64-apple-darwin22  
Configured with: ../configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 13.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=x86_64-apple-darwin22 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk  
Thread model: posix  
Supported LTO compression algorithms: zlib zstd  
gcc version 13.1.0 (Homebrew GCC 13.1.0)  

So, I tried to set the alias for gcc in my .zshrc which showed correct output in terminal but the command to install mysqlclient still fails with same error message. I tried to install multiple packages as suggested in different answers but still the error is same.

2 Answers 2

2

Run brew info zlib to get the path to your zlib.

Likely: "-L/opt/homebrew/opt/zlib/lib"

Open your mysql config file in any editor, example:

> sudo vim /opt/homebrew/opt/mysql-client/bin/mysql_config

In this file you'll find the libraries. I updated zlib to be the direct library

before:

# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lzlib  -lzstd -L/opt/homebrew/opt/[email protected]/lib -lssl -lcrypto -lresolv"

After

# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -L/opt/homebrew/opt/zlib/lib  -lzstd -L/opt/homebrew/opt/[email protected]/lib -lssl -lcrypto -lresolv"

Don't know if it's the most elegant solution but this workaround got me to install mysql_client

Sign up to request clarification or add additional context in comments.

Comments

0

This should be fixed in homebrew with https://github.com/Homebrew/homebrew-core/pull/131207

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.