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
TL;DR
Install the older version (3.4.4) of Imagick forcing it via pecl
pecl install imagick-3.4.4
Intro
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.
Error
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
Top comments (5)
Phew, a lot easier than reinstalling gcc etc. Thanks for this.
Hopefully next releases after 3.5 will address this with a flag during compiling
Thanks alot.
Thank you very much ^^ . Too bad the version 3.4 of imagick is not compatible with PHP 8.0...!
I think it's possible to have 3.4.4 on PHP 8. Check this, there are few suggestions: github.com/Imagick/imagick/issues/331