Installing multiple python packages that requires different LDFLAGS/CPPFLAGS (macOS Big Sur Apple Silicone)

Viewed 283

When installing python requirements from requirements.txt file, there were several packages that required different values in LDFLAGS/CPPFLAGS. first, I got this when installing mysql-client: ld: library not found for -lzstd I solved it by running the pip install like this:

CPPFLAGS="-I/opt/homebrew/include" LDFLAGS="-L/opt/homebrew/lib" pip install mysqlclient

than, I had this issue when installing cryptography:

build/temp.macosx-10.14-arm64-3.8/_openssl.c:575:10: fatal error: 'openssl/opensslv.h' file not found
#include <openssl/opensslv.h>

Solved it by installing it like this:

CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" pip install cryptography

My question is - what is going on here? I want to keep LDFLAGS/CPPFLAGS values in my .zshrc but seems that for every package I need diferent values there?? When working on my old mac I remember that the values were

export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include"

which are the values that are suggested to you by brew after you brew install mysql-client.

1 Answers

As long as they do not conflict with each other, you can put multiple directories in there with something like

LDFLAGS='-L/opt/foo/lib -L/usr/local/bar/lib'

and ditto for CPPFLAGS.

However, personally I'd avoid putting LDFLAGS and CPPFLAGS in .zshrc — as you have found out, the required values often depend on the thing you are compiling, and setting them globally (and then inevitably forgetting about them) is likely to cause confusion at some point in the future.

Related