Fix `ld: library not found for -lgomp` when installing Imagick 3.5 via PHP pecl on Mac

Fix `ld: library not found for -lgomp` when installing Imagick 3.5 via PHP pecl on Mac

Any PHP version, any Imagemagick version, silicon/intel

Update 25 July 2021

As of 22 July 2021, version 3.5.1 is stable in the pecl channel and can be used to compile imagick for both PHP 7 and PHP 8.

pecl install imagick

The general command will not fail anymore


Install the older version (3.4.4) of Imagick forcing it via pecl

pecl install imagick-3.4.4


The last version (3.5) of the PHP extension for Imagemagick ( Imagick ) introduces a compilation error on Apple systems, which is independent from the PHP version (tested on 7.4 and 8) and Imagemagick version (tested on 6.x and 7.x) and is instead related to the missing/broken support for gomp of the gcc compiler.

This is not related to Apple Silicon either, as I've tested on an Intel machine.


The error is thrown while compiling, after running

pecl install imagick

The complete error is

ld: library not found for -lgomp

Potential Fixes

There are several Stack Overflow threads talking about compilation errors due to Gomp. The most comprehensive I've found is this.

I've tried few of the fixes proposed in the answer, but most require compiling a different version of gcc, which would make subsequent updates via homebrew unstable.

Also tried this other amazing thread on Stack Overflow which suggests llvm and revised compiler flags, but it didn't work for this specific case, probably due to built-in parameters in the pecl compilation process.

Actual Fix

In the end the final fix was to downgrade the version of Imagick to 4.3.3, which compiles perfectly.

You can do so either by downloading the release from github or simply by forcing the version in pecl as follows:

pecl install imagick-3.4.4