Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install decimal PHP extension on macOS with M1 – "Could not find libmpdec"

I tried to install the decimal PHP extension using pecl because I need it for an existing project. On my new M1 machine, I got the following error:

$ pecl install decimal
[...]
checking for libmpdec library in default path... Could not find libmpdec
configure: error: Please reinstall libmpdec
ERROR: `/private/tmp/pear/temp/decimal/configure --with-php-config=/opt/homebrew/bin/php-config' failed
like image 496
Martin Avatar asked Oct 16 '25 11:10

Martin


1 Answers

After researching online, I found these threads describing similar issues:

  • Installing php-decimal in MacOS arm64e and can't get libmpdec
  • https://www.reddit.com/r/PHPhelp/comments/nmryxz/trouble_installing_php_extensions_with_valet_and/

Since both threads did not include a compact explanation of what I needed to do to fix the issue, I decided to try and summarize it here.

When pecl tries to install the decimal extension, the libmpdec library is not found in the default library path. The installer tries to find the library in /usr/local/lib/ while Homebrew installs it in /opt/homebrew/lib/. To help the installer get up to speed, create symlinks for the library components and two header files:

sudo mkdir /usr/local/lib
sudo ln -s /opt/homebrew/lib/libmpdec++.2.5.1.dylib /usr/local/lib/libmpdec++.2.5.1.dylib
sudo ln -s /opt/homebrew/lib/libmpdec++.3.dylib /usr/local/lib/libmpdec++.3.dylib
sudo ln -s /opt/homebrew/lib/libmpdec++.a /usr/local/lib/libmpdec++.a
sudo ln -s /opt/homebrew/lib/libmpdec++.dylib /usr/local/lib/libmpdec++.dylib
sudo ln -s /opt/homebrew/lib/libmpdec.2.5.1.dylib /usr/local/lib/libmpdec.2.5.1.dylib
sudo ln -s /opt/homebrew/lib/libmpdec.3.dylib /usr/local/lib/libmpdec.3.dylib
sudo ln -s /opt/homebrew/lib/libmpdec.a /usr/local/lib/libmpdec.a
sudo ln -s /opt/homebrew/lib/libmpdec.dylib /usr/local/lib/libmpdec.dylib

sudo ln -s /opt/homebrew/include/decimal.hh /usr/local/include/decimal.hh
sudo ln -s /opt/homebrew/include/mpdecimal.h /usr/local/include/mpdecimal.h

After creating the symlinks, try to install the decimal extension again:

pecl install decimal

The installation should now work as expected.

like image 51
Martin Avatar answered Oct 18 '25 09:10

Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!