6

I've tried common solutions written for mysqlclient error

  • 1st try: brew install mysql-connector-c
  • 2nd try: LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
  • 3rd try: brew install zstd

And mysql server is well-running. But the error is not being fixed..

I am getting clang linker error saying library not found for -lzstd

    clang -bundle -undefined dynamic_lookup -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/user/.asdf/installs/python/3.7.10/lib -L/usr/local/opt/llvm/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/user/.asdf/installs/python/3.7.10/lib -L/usr/local/opt/llvm/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -L/usr/local/opt/llvm/lib -I/usr/local/opt/llvm/include build/temp.macosx-11.2-x86_64-3.7/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql/8.0.25_1/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-11.2-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.so
ld: library not found for -lzstd
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1
victory
  • 151
  • 2
  • 9

1 Answers1

10

In my case I did not had the sudo access so installed brew for my user Check if your brew is not in default location do this to check where you have installed brew

brew --prefix
output: Users/helloWorld/homebrew

use the output of above to set the ld flags and cpp flags for example for me ssl and zstd libs were not found so this is what i did:

export LDFLAGS="-L/Users/helloWorld/homebrew/lib -L/Users/helloWorld/homebrew/opt/openssl/lib"

export CPPFLAGS="-I/Users/helloWorld/homebrew/include -I/Users/helloWorld/homebrew/opt/openssl/include" 

and then do the pip install

pip3 install mysqlclient
Rahul Rai
  • 116
  • 1
  • 6
  • 1
    Thanks a lot! You saved so much time for me :) – victory Jul 02 '21 at 00:33
  • Happy to help! Cheers! – Rahul Rai Jul 03 '21 at 03:07
  • I've had exactly the same issue, done exactly like Rauhl said, except now it says `ld: can't map file, errno=22 file '/opt/homebrew/opt/openssl/lib' for architecture arm64` :( been struggling with this for 3 days now smh – Ovi Jul 13 '21 at 18:36
  • Hi Ovi, could you share the commands you tried before this error message. – Rahul Rai Jul 14 '21 at 04:40
  • I have made a small edit @Ovi Could you please try again. Earlier somehow i missed a hyphen before the second L. `export LDFLAGS="-L/Users/helloWorld/homebrew/lib -L/Users/helloWorld/homebrew/opt/openssl/lib"` – Rahul Rai Jul 14 '21 at 04:51
  • Hey @RahulRai, I have tried different commands until I got the path of the openssl right, resulting in the error above. One answer that has worked for me, was this one -> https://stackoverflow.com/a/67907401/9686563 – Ovi Jul 20 '21 at 10:03