0

I am trying to use the tch crate for rust but I am getting the following error or run.

Creating library C:\Users\sefto\Documents\rust-projects\tch-test\target\debug\deps\tch_test.lib and object C:\Users\sefto\Documents\rust-projects\tch-test\target\debug\deps\tch_test.exp
          libtorch_sys-457a9014c45a8ec4.rlib(torch_api.o) : error LNK2001: unresolved external symbol __imp___tls_index_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA
          libtorch_sys-457a9014c45a8ec4.rlib(torch_api.o) : error LNK2001: unresolved external symbol __imp___tls_offset_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA
          C:\Users\sefto\Documents\rust-projects\tch-test\target\debug\deps\tch_test.exe : fatal error LNK1120: 2 unresolved externals

This is after running the following commands:

cargo new tch-test
cd tch-test
cargo add tch

Then changing the contents of main.rs to:

use tch::*;

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

and finally running:

cargo run

I have tried installing libtorch and adding to PATH etc as per the install instructions here https://github.com/LaurentMazare/tch-rs.

I have also tried without libtorch as if it is not found cargo should install it for me.

  • It's an [c++ linking](https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work) error. Just found two post [LaurentMazare-issue-563](https://github.com/LaurentMazare/tch-rs/issues/563#issuecomment-1311295542) and [MSVC-feedback](https://developercommunity.visualstudio.com/t/thread_local-causing-fatal-error-LNK1161/10199441), it's a bug on MSVC 2022 17.4. I just run [tch-rs basic tensor operation](https://github.com/LaurentMazare/tch-rs#basic-tensor-operations) without problem on KDE Neon 5.26 and Windows 10 with non-manual install libtorch. – cpprust Jan 30 '23 at 20:33
  • 1
    @cpprust I updated MSVC to 17.4 and it fixed the linking error but now I am getting another error. `error: process didn't exit successfully: `target\debug\tch-test.exe` (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND)`. But I have no idea which dll is missing. I also tried with MSVC 2019 which also fixed the linking error and then had the same dll eroor. – Sefton de Pledge Jan 31 '23 at 20:23

0 Answers0