swift-graphics icon indicating copy to clipboard operation
swift-graphics copied to clipboard

App build fails. 'cairo.h' file not found

Open trentben opened this issue 2 years ago • 7 comments

I'm trying to add the swift-gif package to my project, but I am getting a build error from the Cairo package. I'm running Xcode 14.0.0, I used brew to install Cario, and added the swift-graphics package

I'm getting the following error when trying to build my project 'cairo.h' file not found

Not sure what I am missing here

trentben avatar Dec 31 '22 18:12 trentben

You need to install the Cairo library, for example with Homebrew:

brew install cairo

Edit: Sorry, I was a bit too quick to reply here, didn't see that you already mentioned this

fwcd avatar Dec 31 '22 18:12 fwcd

I installed the Cairo library using Homebrew. I suspect Xcode must not be able to find the library

trentben avatar Dec 31 '22 18:12 trentben

Are you using an Apple Silicon machine? You could try adding /opt/homebrew/include (IIRC, off top of my head) to your include path and /opt/homebrew/lib to your library path.

fwcd avatar Dec 31 '22 20:12 fwcd

I'm using a 2019 Intel Mac running Ventura and just updated to Xcode 14.2. I've been at this for a good part of the afternoon. Been trying to add various combinations of paths to my projects Header and Library Search Paths.

I tried the following Header Search Path

/usr/local/Cellar/cairo/1.16.0_5/include
/usr/local/**`
/usr/local/include

And the following Library Search Paths

/usr/local/lib
/usr/local/Cellar/cairo/1.16.0_5/lib

I also tried installing cairo using MacPorts, and setting my Library and Header Paths accordingly, but the same result

trentben avatar Dec 31 '22 22:12 trentben

So I'm pretty sure I got the header paths configured correctly. I took a closer look today and found this message in the build log. Looks like the library built just for macOS

Ignoring file /usr/local/Cellar/cairo/1.16.0_5/lib/libcairo.dylib, building for iOS-arm64 but attempting to link with file built for macOS-x86_64

Did some searching around and found this form on building Cario for iOS. Honestly, though it may be easier for me to find an alternative way to encode a gif in my iOS project

https://discourse.libcinder.org/t/build-cairo-for-ios/302

trentben avatar Jan 01 '23 17:01 trentben

Unfortunately, I haven't really gotten around to look into iOS support, back when I wrote swift-gif I primarily had Linux support in mind, since I couldn't find a GIF encoder for Swift that supported Linux (or any non-Apple platforms for that matter).

In the medium-term I'm planning to have a CoreGraphics backend in swift-graphics (#6) which would make the Cairo dependency optional on Apple platforms, but for now another GIF library might be a better choice for iOS.

Edit: I've also added https://github.com/fwcd/swift-gif/issues/3, since the GIF library doesn't actually depend on the drawing functionality from swift-graphics and mostly just uses it's Image type.

fwcd avatar Jan 01 '23 17:01 fwcd

After running into this issue in CI too, here's something you could try

brew install pkg-config

fwcd avatar Feb 20 '23 01:02 fwcd