Home > Mobile >  macOS Xcode, how to link/compile libvips as a static lib
macOS Xcode, how to link/compile libvips as a static lib

Time:08-04

I have a small app called Messer. It's a native macOS app using Swift and SwiftUI. The way the app works is by using the native macOS apis to manipulate the image (NSImage) and finally saves a png file to disk. Further conversion to other formats (with optimization) is left to embedded binaries of popular open source libraries.

The problem is that the conversion and manipulation is too slow, for smallish images it's fine, but anything over a mb makes the app choke. I'm looking for ways to (radically) improve the performance and I came across libvips, it even has support for webp. So basically I would like to migrate all the image manipulation code to libvips. However, I'm a complete noob when comes to compilation toolchains and what not.

Could anyone give me a hand and provide some detailed instructions on how would I go about embedding the library in my macOS Xcode project and further then get it to compile statically (due to all the dependencies it has).

I would greatly appreciate it!

Edit: I just realized libvips is GPL which means I cannot embed it without releasing the source code of my app. Which is something I do not want to do. I will leave the question open for future reference though, maybe someone needs it at some point.

CodePudding user response:

A fully static library is difficult, and probably not necessary.

libvips itself is easy to build static, but it has a lot of dependencies (it can be more than 40 other projects), and you'll need to make static versions of all those libraries too. It's a lot of very annoying work.

Instead, I would use homebrew to build a vips area, and take a copy of that.

Wipe your homebrew install area, do a fresh install, then brew install vips. Take a copy of the brew area, trim out stuff you don't need (there's a fair amount you can cut away, you probably only need lib and include, make a script to do this for you), and copy that tree into your project.

You might need to set some environment variables like DYLD_LIBRARY_PATH to get it to link.

You'll need to be careful that you don't include any licensed code. Poppler, for example, which libvips can use for PDF load, is GPL and you mustn't use that. It might be worth making your own libvips binary that only enables the dependencies you want.

I have a repo here:

https://github.com/jcupitt/build-osx

That builds a macOS .app for this thing:

https://github.com/libvips/nip2

It uses jhbuild to make the whole libvips stack from scratch and then package it. I don't think jhbuild is a a good solution for you directly, but you could probably adapt some of the packaging scripts.

  • Related