MacOS brew install libsndfile but still not found

Viewed 1860

I just switched from windows to mac, and I was trying to use brew to install libsndfile for one of my C projects. But after installing it still shows cannot find it error in the terminal, and I seems not be able to figure out why.

brew install libsndfile libsndfile 1.0.31 is already installed and up-to-date.

gcc -lm -lsndfile -o skeleton skeleton.c fatal error: 'sndfile.h' file not found

1 Answers

This is likely because, since M1, Homebrew installs by default to /opt/homebrew and you will need to instruct it explicitly where to find the include and library files.

Try:

export CPATH=/opt/homebrew/include
export LIBRARY_PATH=/opt/homebrew/lib

..and then recompile. Add the above lines to your shell .zprofile (or .profile) to persist the settings for future use.

Related