For work I'm trying to wrap a 3rd party DLL so I can prototype something in Rust. I've done a lot of this sort of FFI stuff in the past, but it's mainly been calling a Rust Shared Object/DLL from other languages. Now that I'm trying to go in the other direction for a non-trivial program I've started encountering linker errors when compiling the *-sys
crate on Windows (the target platform).
In my foo-sys/Cargo.toml
I've added a links = "foo"
line to let cargo
know this crate links to the foo
system library. In foo-sys/build.rs
I'm also making sure to print out "cargo:rustc-link-lib=foo"
, which will presumably adds the equivalent of -lfoo
to the linker args.
What I'm currently doing doesn't seem to be working because when I try to run the foo-sys
smoke test I'm getting linker errors. Are there any good example build.rs
scripts where people have had to link to pre-installed DLLs dynamically on Windows when you can't build from source?
Amusingly when I was trying this on my Linux laptop using cross
and cross-compiling to i686-pc-windows-gnu
, everything Just Worked