Fdrph
Fdrph

Reputation: 11

Statically linking libvips to a Rust program in Windows

There is a lib-sys for libvips on crates.io, however it uses pkg-config which searches the system for the library to link to dynamically, not statically.

I want to provide libvips with the final binary of my software in .dll or .exe along with it since the user should only install one executable with everything in it, C and Rust code.

Looking at the Rust book's FFI linking section, we can link lib.a files easily, but libvips is a huge complex C library that has releases for Windows in .dll and .exe format. I do not know how to link these Windows binaries of libvips to a Rust program statically.

Potentially, I could build it from source manually and link it manually, but the build process seems very complex and it uses scripts and Docker. I would have to replace those scripts with a build.rs of my own that did the same but that seems very hard to me since I'm a beginner at this. I know I would have to set rustc-link-search in build.rs, but I don't know how to compile the .a files for libvips. Rust book on this

My goal is to FFI into libvips from Rust. I am using Windows 10 and want to cargo build the project and have the Rust code and libvips in one distributable binary with no other dependencies.

edit-1: the vips-dev-w64-web-x.y.z.zip contains libvips.lib , libvips.dll.a files, pkgconfig .pc files, as well as the normal .dll and vips.exe. Can i use these .lib and .a files and if so exactly how? Will it link statically? Are these .pc files useful for my situation?

Upvotes: 1

Views: 1012

Answers (1)

jcupitt
jcupitt

Reputation: 11190

Just ship the libvips bin area in your tree somewhere, add it to PATH on startup, and link dynamically. This is how electron apps and node.js packages that use libvips work. Static linking for complex libraries died a while ago, it's not worth trying.

As much as anything, it would be a potential licence violation. libvips is LGPL, so you MUST link dynamically (or include enough of your code to allow relinking), or your whole application becomes open source.

Upvotes: 0

Related Questions