1

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

titoco3000
  • 51
  • 1
  • 6

2 Answers2

1

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.

titoco3000
  • 51
  • 1
  • 6
0

As mentioned in the docs, you can link pytorch statically by exporting LIBTORCH_STATIC=1 environment variable before compilation. Full docs here.

As for target-feature=+crt-static, it affects only C Runtime (crt is abbreviation from it) so it would just link Visual C++ Runtime into your application and wouldn't affect other DLLs. Since PyTorch is not a part of C Runtime, it wouldn't affect it any way.