DEV Community

Andrea Olivato
Andrea Olivato

Posted on • Updated on • Originally published at coding.andreaolivato.com

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

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The complete error is

ld: library not found for -lgomp
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
 
alancwoo profile image
Alan

Phew, a lot easier than reinstalling gcc etc. Thanks for this.

Collapse
 
andreaolivato profile image
Andrea Olivato

Hopefully next releases after 3.5 will address this with a flag during compiling

Collapse
 
phillipmwaniki profile image
Phillip Mwaniki Nzuli

Thanks alot.

Collapse
 
nek_dev profile image
Maxime Veber

Thank you very much ^^ . Too bad the version 3.4 of imagick is not compatible with PHP 8.0...!

Collapse
 
andreaolivato profile image
Andrea Olivato

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