- 1 year ago
Statically linking libvips to a Rust program in Windows
Statically linking libvips to a Rust program on Windows can be a bit challenging due to the different build systems involved. However, it is possible by using the appropriate build tools and configuration. Here's a step-by-step guide to statically link libvips to a Rust program on Windows:
Download and Install libvips:
First, download the libvips precompiled binaries for Windows from the official website: https://libvips.github.io/libvips/. Choose the appropriate version (32-bit or 64-bit) based on your Rust program's architecture. After downloading, install libvips by extracting the zip file to a known location on your system.Set Environment Variables:
Set the environment variables required for the build process. Open a Command Prompt window, and set the following environment variables to point to the libvips installation location:batchset VIPS_INCLUDE_PATH=C:\path\to\libvips\include
set VIPS_LIBRARY_PATH=C:\path\to\libvips\lib
Replace
C:\path\to\libvips
with the actual path to your libvips installation.Cargo Configuration:
Update your Rust project's Cargo.toml file to specify the build dependencies and link to libvips. Add the following lines to the Cargo.toml:toml[build-dependencies]
vips-sys = "0.17"
[target.'cfg(windows)'.vips]
has_pkg_config = false
pkg_config = "vips"
include_search_paths = ["C:/path/to/libvips/include"]
library_search_paths = ["C:/path/to/libvips/lib"]
Replace
C:/path/to/libvips
with the actual path to your libvips installation.Create vips.pc File (Optional):
The vips-sys crate uses pkg-config to locate libvips during the build process. Since Windows doesn't typically use pkg-config, you can create a vips.pc file manually to provide the necessary information to the vips-sys crate. Create a file named vips.pc with the following contents:makefileName: vips
Description: A powerful image processing library
Version: 8.10.6
Libs: -L${libdir} -lvips
Cflags: -I${includedir}
Save this file to a location where Cargo can find it (e.g., the root of your project directory).
Build Your Rust Project:
Now you can build your Rust project as usual using Cargo. The vips-sys crate will use the configuration in Cargo.toml to find and link libvips statically to your Rust program.arduinocargo build --release
Note: Make sure to use the appropriate vips-sys version in your Cargo.toml. The version shown in this guide (0.17) may be outdated; check the latest version on crates.io.
That's it! If all steps are followed correctly, your Rust program should now be statically linked with libvips on Windows. Remember to adjust the paths in the Cargo.toml and environment variables to match your libvips installation location.