Search code examples
ruby-on-railsmacosrubygemsclangzsh

Ruby on Rails webp-ffi gem installation fails. Can't find C header files


Mac OS Big Sur M1 Chip Ruby 2.6.6 Rails 6.0.4

sudo gem install webp-ffi

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

    current directory: /Users/$MYUSERNAME/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webp-ffi-0.3.1/ext/webp_ffi
/Users/$MYUSERNAME/.rbenv/versions/2.6.6/bin/ruby -rrubygems /Users/$MYUSERNAME/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.6/exe/rake RUBYARCHDIR\=/Users/$MYUSERNAME/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/webp-ffi-0.3.1 RUBYLIBDIR\=/Users/$MYUSERNAME/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/webp-ffi-0.3.1
mkdir -p aarch64-darwin
clang -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -DHAVE_PUTS=1 -DHAVE_WEBPDECODERCONFIG=1 -DHAVE_WEBPGETINFO=1 -DHAVE_STDIO_H=1 -o aarch64-darwin/jpegdec.o -c ./jpegdec.c
./jpegdec.c:4:10: fatal error: 'jpeglib.h' file not found
#include <jpeglib.h>
         ^~~~~~~~~~~
1 error generated.
rake aborted!
Command failed with status (1): [clang -fexceptions -O -fno-omit-frame-poin...]

Tasks: TOP => default => aarch64-darwin/libwebp_ffi.bundle => aarch64-darwin/jpegdec.o
(See full trace by running task with --trace)

rake failed, exit code 1

I have ensured that webp is installed as well as other webp-ffi dependencies. I have ensured that xcode and command line tools are installed and up to date. I have accepted the license agreement for xcode. I have located the header file (jpeglib.h) on my system, I can give the path if need be. I believe this is an error with where clang is looking for the header files but edits I make to environment variables in my ~/.zshrc file do not seem to have an affect.

Please let me know if there is any other information you need to help work on the problem.


Solution

  • I solved this by uninstalling everything (node.js, ruby, rbenv, homebrew, etc.) and redoing the whole install process using Rosetta.

    To use Rosetta right click on your Terminal application, go to 'Get Info', and check the 'Launch Using Rosetta' checkbox