Linking libvips statically


#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. Most FFI tutorials dabble in .a files in linux envs, but I am on windows, and I’m not familiar with anything about what I’m trying to do on windows, also the tutorials mostly build from source using gcc or cc-rs, but libvips has it’s own build scripts that are very complex. Hence me trying to use the .lib files.

I ask for any help in setting up an environment where i can call libvips from rust on windows and get a single binary for redistribution when I cargo build the project. End users won’t have pkg-config and libvips installed on their windows machines, which is why the crate vips-sys is useless to me.


#2

In order to link to libvips statically all you have to do is obtain the static library version of libvips and then link to it normally. Linking dynamically and statically are actually almost identical, because in either case you just link to libvips.lib. The key difference is whether libvips.lib itself is an import library or a static library. Unfortunately the libvips.lib from that download is an import library so you’ll have to either find another prebuilt source that has it as a static library or build libvips yourself.


#4

Then my only chance is linking dynamically. How do I distribute the program after compilation while linking dynamically? Remember, the end goal is just that the user installs one program on windows, if I can achieve this linking dynamically with the import library I have I’m fine with it.


#5

pkg-config is only used when you cargo build. End users don’t need it. pkg-config finds the location of libvips and passes to rust compiler. If you already know the path of libvips, you don’t even need pkg-config.

You can write build.rs and try the following. See docs.

cargo:rustc-link-lib=static=foo
cargo:rustc-link-search=native=/path/to/foo

I created two issues in vips-sys for Windows and static linking. I am not on Windows and static linking is not easy (automate downloading libvips code and dependencies and build), so it will take time.

See build.rs in other crates that work for cross-platform and provide dynamic/static linking.

rust-openssl build.rs
curl-rust build.rs


#6

Alas, if you link dynamically you will have to distribute the dll with your program. You’ll either have to distribute a zip file containing both the .exe and the .dll, or you’ll need an installer that installs them both.