rcairo / rcairo

The Ruby bindings for cairo.
https://rcairo.github.io/
Other
134 stars 31 forks source link

Error installing on macOS #77

Closed joao closed 1 year ago

joao commented 1 year ago

I'm having trouble installing the cairo gem, which is returning a 'Could not create Makefile due to some reason' error.

Have searched through closed issues, with similar output and most errors with a gem install cairo are due to a mismatch between pkg-config and cairo.

I have pkg-config v1.49 and trying to install the lasted cairo gem, v1.17.8. Tried different Ruby versions (v2.7.6 and v3.1.2), installed via rbenv, and same error was returned.

Any pointers for further debugging or a fix?

kou commented 1 year ago

Could you share full logs?

kou commented 1 year ago

Could you also share your system information?

joao commented 1 year ago

system: macOS 10.15 ruby version: 3.1.2 or 2.7.6, via rbenv pkg-config version: 1.4.9

gem install cairo log:

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

    current directory: /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/cairo-1.17.8/ext/cairo
/Users/joao/.rbenv/versions/3.1.2/bin/ruby -I /Users/joao/.rbenv/versions/3.1.2/lib/ruby/3.1.0 -r ./siteconf20221104-49669-758e27.rb extconf.rb
checking for GCC... yes
checking for Homebrew... yes
checking for cairo version (>= 1.2.0)... yes (1.16.0)
*** 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
    --without-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=/Users/joao/.rbenv/versions/3.1.2/bin/$(RUBY_BASE_NAME)
    --with-pkg-config
    --without-pkg-config
    --with-override-variables
    --without-override-variables
/Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:389:in `parse_pc': .pc doesn't exist: <fontconfig> (PackageConfig::NotFoundError)
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:233:in `declaration'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:178:in `requires_private'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:509:in `block in all_required_packages'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:259:in `collect_requires'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:265:in `block in collect_requires'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:260:in `each'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:260:in `collect_requires'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:508:in `all_required_packages'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:283:in `collect_cflags'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:191:in `cflags_only_other'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:569:in `cflags_only_other'
    from /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/pkg-config-1.4.9/lib/pkg-config.rb:621:in `have_package'
    from extconf.rb:42:in `required_pkg_config_package'
    from extconf.rb:50:in `<main>'

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

  /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-darwin-19/3.1.0/cairo-1.17.8/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/cairo-1.17.8 for inspection.
Results logged to /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-darwin-19/3.1.0/cairo-1.17.8/gem_make.out

mkmf.log file:

checking for GCC... -------------------- yes

DYLD_FALLBACK_LIBRARY_PATH=.:/Users/joao/.rbenv/versions/3.1.2/lib "clang -o conftest -I/Users/joao/.rbenv/versions/3.1.2/include/ruby-3.1.0/x86_64-darwin19 -I/Users/joao/.rbenv/versions/3.1.2/include/ruby-3.1.0/ruby/backward -I/Users/joao/.rbenv/versions/3.1.2/include/ruby-3.1.0 -I. -I/Users/joao/.rbenv/versions/3.1.2/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -fno-common -pipe conftest.c  -L. -L/Users/joao/.rbenv/versions/3.1.2/lib -L. -L/Users/joao/.rbenv/versions/3.1.2/lib  -fstack-protector-strong -L/usr/local/lib     -lruby.3.1   "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

DYLD_FALLBACK_LIBRARY_PATH=.:/Users/joao/.rbenv/versions/3.1.2/lib "clang -I/Users/joao/.rbenv/versions/3.1.2/include/ruby-3.1.0/x86_64-darwin19 -I/Users/joao/.rbenv/versions/3.1.2/include/ruby-3.1.0/ruby/backward -I/Users/joao/.rbenv/versions/3.1.2/include/ruby-3.1.0 -I. -I/Users/joao/.rbenv/versions/3.1.2/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -fno-common -pipe   -c conftest.c"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: /*top*/
4: #ifndef __GNUC__
5: # error
6: |:/ === __GNUC__ undefined === /:|
7: #endif
/* end */

--------------------

checking for Homebrew... -------------------- yes

--------------------

have_package: checking for cairo version (>= 1.2.0)... -------------------- yes (1.16.0)

--------------------
kou commented 1 year ago

Could you also show the outputs of the following command lines?

$ ls -lah $(brew --prefix)/lib/pkgconfig/
$ cat $(brew --prefix)/lib/pkgconfig/fontconfig.pc
joao commented 1 year ago

$ ls -lah $(brew --prefix)/lib/pkgconfig/
https://gist.github.com/joao/826db18a8a0ffcf54a69ee2156daed50

cat $(brew --prefix)/lib/pkgconfig/fontconfig.pc

prefix=/usr/local/Cellar/fontconfig/2.14.0
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
sysconfdir=/usr/local/etc
localstatedir=/usr/local/var
PACKAGE=fontconfig
confdir=${sysconfdir}/fonts
cachedir=${localstatedir}/cache/${PACKAGE}

Name: Fontconfig
Description: Font configuration and customization library
Version: 2.14.0
Requires:  freetype2 >= 21.0.15
Requires.private:  expat
Libs: -L${libdir} -lfontconfig
Libs.private:  
Cflags: -I${includedir}  

The first time I run the fontconfig.pc command, it was missing said file, because altough it was installed, it wasn't linked by Homebrew. I fixed it and now returns the above output.

Despite this, gem install cairo, still returned an error, but now not related to fontconfig.pc, but with freetype2. Once again went to check Homebrew, and freetype wasn't linked, so I fixed it. Then the error was libpng... seems there are too many brews unlinked, which is weird, has I didn't upgraded my operating system.

To fix this I decided to link all brews again, running:
brew list -1 | while read line; do brew unlink $line; brew link --force $line; done

But still there was an error with libpng, so I had to run:
brew link --overwrite libpng

So I tried to install cairo again and, with 'dependencies' issues solved, now threw a different error:

In file included from rb_cairo.c:17:  
./rb_cairo.h:20:10: fatal error: 'cairo.h' file not found

screenshot 2022-11-04 at 14 50 02

Now seems to be some issue with build file locations, any further pointers? Thank you!

kou commented 1 year ago

Could you show the outputs of them?

$ cat $(brew --prefix)/lib/pkgconfig/cairo.pc
$ pkg-config --cflags --libs --debug cairo
joao commented 1 year ago

Here they are: https://gist.github.com/joao/7508a146a6ec896e0897830bec9bccab

Placed them in a gist as one is really long. Thank you.

kou commented 1 year ago

Could you show /Users/joao/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/cairo-1.17.8/ext/cairo/Makefile?

joao commented 1 year ago

Here it is:
https://gist.github.com/joao/12573e619b37de02e12710fcb14a7398

kou commented 1 year ago

Could you show the outputs of them?

$ brew --prefix cairo
$ ls -lah $(brew --prefix cairo)
$ ls -lah /usr/local/Cellar/cairo/1.16.0_1/include/cairo
joao commented 1 year ago
$ brew --prefix cairo
/usr/local/opt/cairo

$ ls -lah $(brew --prefix cairo)
lrwxr-xr-x  1 joao  admin    34B Nov  4 14:22 /usr/local/opt/cairo -> ../Cellar/cairo/1.16.0_1.reinstall

$ ls -lah /usr/local/Cellar/cairo/1.16.0_1/include/cairo
ls: /usr/local/Cellar/cairo/1.16.0_1/include/cairo: No such file or directory
kou commented 1 year ago

This (.reinstall suffix) is strange:

lrwxr-xr-x  1 joao  admin    34B Nov  4 14:22 /usr/local/opt/cairo -> ../Cellar/cairo/1.16.0_1.reinstall

Could you reinstall Homebrew's cairo formula?

joao commented 1 year ago

It worked, but not with the reinstall.

Used first: brew uninstall --ignore-dependencies cairo And as there were multiple versions installed, had to do: brew uninstall --force cairo

Then doing: brew install cairo And: gem install cairo Worked successfully.

Weird, has I had reinstalled the Cairo formula while debugging. Guess I had to removed it first completely.

Thank you for your persistence, patience and helping solve this issue.

kou commented 1 year ago

Good to know. :-) I close this.