Search code examples
phpdecimalapple-m1pecl

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

Solution

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

    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.