rustcross-compilingblosc

"lld-link: error: could not open 'blosc.lib' " for cross-compiling in Rust (Linux->Windows)


I'm trying to cross-compile a Rust program on Linux to Windows. This program contains a function that uses Blosc. A minimal reproducible example can be done with
> cargo init
> cargo add blosc

and adding a function to main.rs using blosc

fn main() {
    println!("Hello, world!");
}

fn decompress(bytes: Vec<u8>) {
    let _: Vec<u8> = unsafe { blosc::decompress_bytes(&bytes).unwrap() };
}

(not adding the function does not cause the error)

When trying to build the program for windows, an error happens:

jojo:~/Documents/projects/test/minimal_blosc$ cargo-xwin  build --bins --release --target x86_64-pc-windows-msvc -vv
       Fresh unicode-ident v1.0.18
       Fresh proc-macro2 v1.0.95
       Fresh quote v1.0.40
       Fresh libc v0.2.172
       Fresh blosc-sys v1.21.0
       Fresh syn v2.0.101
       Fresh thiserror-impl v1.0.69
       Fresh thiserror v1.0.69
       Fresh blosc v0.2.1
   Compiling minimal_blosc v0.1.0 (/home/jojo/Documents/projects/test/minimal_blosc)
     Running `CARGO='/home/jojo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo' CARGO_BIN_NAME=minimal_blosc CARGO_CRATE_NAME=minimal_blosc CARGO_MANIFEST_DIR='/home/jojo/Documents/projects/test/minimal_blosc' CARGO_MANIFEST_PATH='/home/jojo/Documents/projects/test/minimal_blosc/Cargo.toml' CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=minimal_blosc CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/home/jojo/Documents/projects/test/minimal_blosc/target/release/deps:/home/jojo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' /home/jojo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name minimal_blosc --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=236 --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=ca97ec26170b3de9 --out-dir '/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps' --target x86_64-pc-windows-msvc -C linker=lld-link -C strip=debuginfo -L 'dependency=/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps' -L 'dependency=/home/jojo/Documents/projects/test/minimal_blosc/target/release/deps' --extern 'blosc=/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps/libblosc-36bccbde2c6e86bf.rlib' -C linker-flavor=lld-link '-Lnative=/home/jojo/.cache/cargo-xwin/xwin/crt/lib/x86_64' '-Lnative=/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64' '-Lnative=/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/ucrt/x86_64' -L native=/usr/local/lib`

error: linking with `lld-link` failed: exit status: 1
  |
  = note:  "lld-link" "-flavor" "link" "/NOLOGO" "/tmp/rustcW85FVP/symbols.o" "<2 object files omitted>" "/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps/{libblosc-36bccbde2c6e86bf.rlib,libthiserror-1b4754580b1ef82b.rlib,libblosc_sys-01c558d7905cb983.rlib}.rlib" "<sysroot>/lib/rustlib/x86_64-pc-windows-msvc/lib/{libstd-*,libpanic_unwind-*,libwindows_targets-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libunwind-*,libcfg_if-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "blosc.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/kernel32.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/kernel32.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/advapi32.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/ntdll.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/userenv.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/ws2_32.lib" "/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64/dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:/home/jojo/.cache/cargo-xwin/xwin/crt/lib/x86_64" "/LIBPATH:/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64" "/LIBPATH:/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/ucrt/x86_64" "/LIBPATH:/usr/local/lib" "/OUT:/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps/minimal_blosc.exe" "/OPT:REF,ICF" "/DEBUG" "/PDBALTPATH:%_PDB%"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: lld-link: error: could not open 'blosc.lib': No such file or directory
          

warning: `minimal_blosc` (bin "minimal_blosc") generated 1 warning
error: could not compile `minimal_blosc` (bin "minimal_blosc") due to 1 previous error; 1 warning emitted

Caused by:
  process didn't exit successfully: `CARGO='/home/jojo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo' CARGO_BIN_NAME=minimal_blosc CARGO_CRATE_NAME=minimal_blosc CARGO_MANIFEST_DIR='/home/jojo/Documents/projects/test/minimal_blosc' CARGO_MANIFEST_PATH='/home/jojo/Documents/projects/test/minimal_blosc/Cargo.toml' CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=minimal_blosc CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/home/jojo/Documents/projects/test/minimal_blosc/target/release/deps:/home/jojo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' /home/jojo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name minimal_blosc --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=236 --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=ca97ec26170b3de9 --out-dir '/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps' --target x86_64-pc-windows-msvc -C linker=lld-link -C strip=debuginfo -L 'dependency=/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps' -L 'dependency=/home/jojo/Documents/projects/test/minimal_blosc/target/release/deps' --extern 'blosc=/home/jojo/Documents/projects/test/minimal_blosc/target/x86_64-pc-windows-msvc/release/deps/libblosc-36bccbde2c6e86bf.rlib' -C linker-flavor=lld-link '-Lnative=/home/jojo/.cache/cargo-xwin/xwin/crt/lib/x86_64' '-Lnative=/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/um/x86_64' '-Lnative=/home/jojo/.cache/cargo-xwin/xwin/sdk/lib/ucrt/x86_64' -L native=/usr/local/lib` (exit status: 1)

I tried getting the blosc.lib by compiling c-blosc myself, even on a windows machine, but I did not succeed. (I cannot build the program on the windows machine though).

Is there a way to either get blosc.lib from somewhere or to solve the error in some other way?


Solution

  • I finally did it with installing Blosc on a windows machine with pip.

    The blosc.lib then showed up in the environment, I installed it in (you can search via dir /s c:\blosc.lib)

    Transfer that to the linux machine where your cargo.toml is. Apparently it has to be in the same directory as the cargo.toml, since according to the command above, it just searches for blosc.lib without any path given, ergo the cargo.toml directory.

    Now it compiled succesfully