rustdllrust-cargolibtorch

Rust include DLL in release


Im in windows, trying to build a release of a project that uses rust's torch crate. To install it, I simply added to Cargo.toml:

[dependencies]
tch = "0.4.0"

If I do cargo run, it goes ok. But if I execute the produced .exe, I get these errors:

torch_cu.dll not found
c10.dll not found

I tried downloading a compiled version of libtorch and including everything from its /lib/ to the same folder, now with the error:

procedure entry point not found

I tried statically linking everything by adding a .cargo/config.toml to my project, with the contents:

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

as suggested by this post, but nothing changed.

I wasnt able to understand what the tch's readme said about it either.

How do I work with these sort of issues? Thanks for any help! Im new to working on these sort of linking errors...

The sandbox-project I was trying these solutions: https://github.com/titoco3000/torch_test


Solution

  • For anyone with the same issue as I was... I think the version of libtorch that the tch-rs crate uses is not the latest, because just copy-pasting all dlls from libtorch/lib to the same folder didnt work; but copying all dlls that were placed by rust at

    \target\debug\build\torch-sys-cba3ef2adb59743a\out\libtorch\libtorch\lib\

    to

    \target\debug\

    does the work! It seens like an terrible solution, but at least works.