rmagick / rmagick

Ruby bindings for ImageMagick
https://rmagick.github.io/
MIT License
709 stars 138 forks source link

Rmagick - Gem::Ext::BuildError: ERROR: Failed to build gem native extension #1310

Closed Anthogr closed 2 years ago

Anthogr commented 2 years ago

I installed pkg-config and imagemagick:

brew install pkg-config imagemagick@6

Imagemagick version

identify -version
Version: ImageMagick 6.9.12-28 Q16 arm 2021-10-29 https://imagemagick.org

When trying to install rmagick

gem install rmagick

I get

Building native extensions. This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

    current directory: /opt/homebrew/lib/ruby/gems/3.0.0/gems/rmagick-4.2.3/ext/RMagick
/opt/homebrew/opt/ruby/bin/ruby -I /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0 -r ./siteconf20211112-33588-cd2c64.rb extconf.rb
checking for brew... yes
checking for Ruby version >= 2.3.0... yes
checking for pkg-config... yes
/opt/homebrew/Library/Homebrew/shims/mac/super/pkg-config: line 9: /pkg-config/bin/pkg-config: No such file or directory
/opt/homebrew/Library/Homebrew/shims/mac/super/pkg-config: line 9: exec: /pkg-config/bin/pkg-config: cannot execute: No such file or directory

ERROR: Can't install RMagick 4.2.3.
Can't find the ImageMagick library or one of the dependent libraries.
Check the mkmf.log file for more detailed information.

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/opt/homebrew/Cellar/ruby/3.0.2_1/bin/$(RUBY_BASE_NAME)

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /opt/homebrew/lib/ruby/gems/3.0.0/extensions/arm64-darwin-20/3.0.0/rmagick-4.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /opt/homebrew/lib/ruby/gems/3.0.0/gems/rmagick-4.2.3 for inspection.
Results logged to /opt/homebrew/lib/ruby/gems/3.0.0/extensions/arm64-darwin-20/3.0.0/rmagick-4.2.3/gem_make.out

So I created a folder /opt/homebrew/Library/Homebrew/shims/mac/super/pkg-config/bin/ containing a symbolic link

ln -s /opt/homebrew/opt/pkg-config/bin/pkg-config pkg-config

And now when trying to install rmagick I get:

Building native extensions. This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

    current directory: /opt/homebrew/lib/ruby/gems/3.0.0/gems/rmagick-4.2.3/ext/RMagick
/opt/homebrew/opt/ruby/bin/ruby -I /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0 -r ./siteconf20211112-33523-27c8up.rb extconf.rb
checking for brew... yes
checking for Ruby version >= 2.3.0... yes
checking for pkg-config... yes
checking for outdated ImageMagick version (<= 6.7.7)... no
checking for clang... yes

Warning: Found more than one ImageMagick installation. This could cause problems at runtime.
         /opt/homebrew/opt/imagemagick@6/bin/Magick-config reports version 6.9.12-28 Q16 is installed in /opt/homebrew/Cellar/imagemagick@6/6.9.12-28
         /opt/homebrew/bin/Magick-config reports version 6.9.12-28 Q16 is installed in /opt/homebrew/Cellar/imagemagick@6/6.9.12-28
Using 6.9.12-28 Q16 from /opt/homebrew/Cellar/imagemagick@6/6.9.12-28.

checking for __GNUC__... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/opt/homebrew/Cellar/ruby/3.0.2_1/bin/$(RUBY_BASE_NAME)
/opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:597:in `block in try_compile'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:546:in `with_werror'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:597:in `try_compile'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:864:in `macro_defined?'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:1006:in `block in have_macro'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:971:in `block in checking_for'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:331:in `open'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:361:in `block in postpone'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:331:in `open'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:357:in `postpone'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:970:in `checking_for'
    from /opt/homebrew/Cellar/ruby/3.0.2_1/lib/ruby/3.0.0/mkmf.rb:1005:in `have_macro'
    from extconf.rb:99:in `configure_compile_options'
    from extconf.rb:19:in `initialize'
    from extconf.rb:398:in `new'
    from extconf.rb:398:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /opt/homebrew/lib/ruby/gems/3.0.0/extensions/arm64-darwin-20/3.0.0/rmagick-4.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /opt/homebrew/lib/ruby/gems/3.0.0/gems/rmagick-4.2.3 for inspection.
Results logged to /opt/homebrew/lib/ruby/gems/3.0.0/extensions/arm64-darwin-20/3.0.0/rmagick-4.2.3/gem_make.out

It is specified I have to install development tools so I checked if it was installed:

gcc -v

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I've been searching for a long time now and found several topics dealing with similar issues but none of them could help me...

Do you have an idea why this doesn't work ?

I'm using Mac OSX 11.6, ruby 3.0.2p107

Thanks a lot

mockdeep commented 2 years ago

@Watson1978 any ideas?

Watson1978 commented 2 years ago

Hmm, the current setup script does not assume an Apple M1 environment...

If Homebrew has been properly installed, RMagick should install successfully. https://github.com/rmagick/rmagick/blob/ba3a6cb90a44551a04b0c74fd5c0579d1f747445/ext/RMagick/extconf.rb#L27

Watson1978 commented 2 years ago

I doubt that pkg-config is installed correctly. Please report the results of running pkg-config --list-all on your terminal.

$ pkg-config --list-all
...
libpcre32           libpcre32 - PCRE - Perl compatible regular expressions C library with 32 bit character support
libxslt             libxslt - XSLT library version 2.
Anthogr commented 2 years ago

~Hmm, the current setup script does not assume an Apple M1 environment...~

If Homebrew has been properly installed, RMagick should install successfully.

https://github.com/rmagick/rmagick/blob/ba3a6cb90a44551a04b0c74fd5c0579d1f747445/ext/RMagick/extconf.rb#L27

I have this same line in the extconf.rb

pkg_config_path = "#{`brew --prefix imagemagick@6`.strip}/lib/pkgconfig"

I doubt that pkg-config is installed correctly. Please report the results of running pkg-config --list-all on your terminal.

$ pkg-config --list-all
...
libpcre32           libpcre32 - PCRE - Perl compatible regular expressions C library with 32 bit character support
libxslt             libxslt - XSLT library version 2.
$ pkg-config --list-all
gmodule-no-export-2.0 GModule - Dynamic module loader for GLib
Wand-6.Q16            MagickWand - MagickCore - C API for ImageMagick (ABI Q16)
ImageMagick++-6.Q16   ImageMagick++ - Magick++ - C++ API for ImageMagick (ABI Q16)
apr-1                 APR - The Apache Portable Runtime library
python3               Python - Build a C extension for Python
libhwy-contrib        libhwy-contrib - Additions to Highway: image and math library
libhwy                libhwy - Efficient and performance-portable SIMD wrapper
MagickWand-6.Q16      MagickWand - MagickWand - C API for ImageMagick (ABI Q16)
python-3.9            Python - Build a C extension for Python
netcdf                netCDF - NetCDF Client Library for C
ImageMagick           ImageMagick - ImageMagick - convert, edit, and compose images (ABI Q16)
libcares              c-ares - asynchronous DNS lookup library
libedit               libedit - command line editor library provides generic line editing, history, and tokenization functions.
Imath                 Imath - Imath library: vector/matrix and math operations, plus the half type.
libpng                libpng - Loads and saves PNG files
libpcreposix          libpcreposix - PCREPosix - Posix compatible interface to libpcre
libcurl               libcurl - Library to transfer files with ftp, http, etc.
gio-unix-2.0          GIO unix specific APIs - unix specific headers for glib I/O library
libwebpmux            libwebpmux - Library for manipulating the WebP graphics format container
libbrotlienc          libbrotlienc - Brotli encoder library
libwebp               libwebp - Library for the WebP graphics format
libbrotlicommon       libbrotlicommon - Brotli common dictionary library
libwebpdemux          libwebpdemux - Library for parsing the WebP graphics format container
libjxl_threads        libjxl_threads - JPEG XL multi-thread runner using std::threads.
libpcre16             libpcre16 - PCRE - Perl compatible regular expressions C library with 16 bit character support
lcms2                 lcms2 - LCMS Color Management Library
zlib                  zlib - zlib compression library
mpfr                  mpfr - C library for multiple-precision floating-point computations
libbrotlidec          libbrotlidec - Brotli decoder library
freetype2             FreeType 2 - A free, high-quality, and portable font engine.
libjxl                libjxl - Loads and saves JPEG XL files
gio-2.0               GIO - glib I/O library
Wand                  MagickWand - MagickCore - C API for ImageMagick (ABI Q16)
yaml-0.1              LibYAML - Library to parse and emit YAML
x265                  x265 - H.265/HEVC video encoder
libhwy-test           libhwy-test - Efficient and performance-portable SIMD wrapper, test helpers.
gthread-2.0           GThread - Thread support for GLib
liblzma               liblzma - General purpose data compression library
gsl                   GSL - GNU Scientific Library
ImageMagick-6.Q16     ImageMagick - ImageMagick - convert, edit, and compose images (ABI Q16)
MagickCore            MagickCore - MagickCore - C API for ImageMagick (ABI Q16)
libde265              libde265 - H.265/HEVC video decoder.
libffi                libffi - Library supporting Foreign Function Interfaces
apr-util-1            APR Utils - Companion library for APR
libheif               libheif - HEIF image codec.
python-3.9-embed      Python - Embed Python into an application
expat                 expat - expat XML parser
libiodbc              iODBC - iODBC Driver Manager
libwebpdecoder        libwebpdecoder - Library for the WebP graphics format (decode only)
sqlite3               SQLite - SQL database engine
lqr-1                 lqr-1 - LiquidRescale seam-carving library
libvmaf               libvmaf - VMAF, Video Multimethod Assessment Fusion
libopenjp2            openjp2 - JPEG2000 library (Part 1 and 2)
isl                   isl - isl Library
libnghttp2            libnghttp2 - HTTP/2 C library
libidn                Libidn - IETF stringprep, nameprep, punycode, IDNA text processing.
OpenEXR               OpenEXR - OpenEXR image library
gmodule-2.0           GModule - Dynamic module loader for GLib
ncurses               ncurses - ncurses 5.7 library
Magick++-6.Q16        Magick++ - Magick++ - C++ API for ImageMagick (ABI Q16)
libxml-2.0            libXML - libXML library version2.
gmodule-export-2.0    GModule - Dynamic module loader for GLib
uuid                  uuid - Universally unique id library
python3-embed         Python - Embed Python into an application
gobject-2.0           GObject - GLib Type, Object, Parameter and Signal Library
libpcre               libpcre - PCRE - Perl compatible regular expressions C library with 8 bit character support
netcdf-fortran        netcdf-fortran - NetCDF Client Library for Fortran
libjpeg               libjpeg - Reads and writes JPEG files
MagickWand            MagickWand - MagickWand - C API for ImageMagick (ABI Q16)
fontconfig            Fontconfig - Font configuration and customization library
libexslt              libexslt - EXSLT Extension library
jbig2dec              libjbig2dec - JBIG2 decoder library.
gmpxx                 GNU MP C++ - GNU Multiple Precision Arithmetic Library (C++ bindings)
ncursesw              ncursesw - ncurses 5.7 library
libtiff-4             libtiff - Tag Image File Format (TIFF) library.
ImageMagick++         ImageMagick++ - Magick++ - C++ API for ImageMagick (ABI Q16)
MagickCore-6.Q16      MagickCore - MagickCore - C API for ImageMagick (ABI Q16)
libzstd               zstd - fast lossless compression algorithm library
libpcrecpp            libpcrecpp - PCRECPP - C++ wrapper for PCRE
Magick++              Magick++ - Magick++ - C++ API for ImageMagick (ABI Q16)
libuv                 libuv - multi-platform support library with a focus on asynchronous I/O.
libpcre32             libpcre32 - PCRE - Perl compatible regular expressions C library with 32 bit character support
glib-2.0              GLib - C Utility Library
libpng16              libpng - Loads and saves PNG files
gmp                   GNU MP - GNU Multiple Precision Arithmetic Library
libxslt               libxslt - XSLT library version 2.
aom                   aom - Alliance for Open Media AV1 codec library v3.2.0.
shared-mime-info      shared-mime-info - Freedesktop common MIME database
Watson1978 commented 2 years ago

Seems pkg-config --list-all works fine. Can you attach /opt/homebrew/lib/ruby/gems/3.0.0/extensions/arm64-darwin-20/3.0.0/rmagick-4.2.3/mkmf.log file in here ?

Anthogr commented 2 years ago

Okay I managed to install rmagick v4.2.3. I uninstalled everything

brew uninstall pkg-config imagemagick@6

reinstalled it

brew install pkg-config imagemagick@6

and installed rmagick

gem install rmagick

This time it worked, I don't know why because I already tried this before with no results... The only thing I did was to restart the mac, maybe one of the path or environment variable needed this to be set ?

Watson1978 commented 2 years ago

I'm glad it worked out. If the error occurs again, feel free to reopen this issue.

Anthogr commented 2 years ago

Thanks a lot for your help !