I get an error when using libtorch in Rust on windows 11

I wanted to create a program in Rust that uses libtorch to read yolo models and identify what is on the screen, but I am stuck at the beginning of the process.

I am using windows 11.

Below is the error at build time and some information that may be relevant.
Can someone please help me?
I am Japanese. Forgive me if my English is strange.

ERROR

PS C:UsersxxxDesktopyolo_screen_capture_rs> cargo build
   Compiling torch-sys v0.5.0
   Compiling opencv v0.92.0
The following warnings were emitted during compilation:

warning: [email protected]: ToolExecError: Command "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" ""C:\libtorch-win-shared-with-deps-2.3.1+cu121\libtorch"\include" "-I" ""C:\libtorch-win-shared-with-deps-2.3.1+cu121\libtorch"\include/torch/csrc/api/include" "-FoC:\Users\xxx\Desktop\yolo_screen_capture_rs\target\debug\build\torch-sys-d2321bf5133b1225\out\19072f24a82f85ae-torch_api.o" "-c" "libtch/torch_api.cpp" with args cl.exe did not execute successfully (status code exit code: 2).

error: failed to run custom build command for `torch-sys v0.5.0`

Caused by:
  process didn't exit successfully: `C:UsersxxxDesktopyolo_screen_capture_rstargetdebugbuildtorch-sys-874e9c7041f962a4build-script-build` (exit code: 1)
  --- stderr


  error occurred: Command "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" ""C:\libtorch-win-shared-with-deps-2.3.1+cu121\libtorch"\include" "-I" ""C:\libtorch-win-shared-with-deps-2.3.1+cu121\libtorch"\include/torch/csrc/api/include" "-FoC:\Users\xxx\Desktop\yolo_screen_capture_rs\target\debug\build\torch-sys-d2321bf5133b1225\out\19072f24a82f85ae-torch_api.o" "-c" "libtch/torch_api.cpp" with args cl.exe did not execute successfully (status code exit code: 2).

List of Environment Variables

PS C:Usersxxx> Get-ChildItem Env:
Name                           Value
----                           -----

CUDA_PATH                      C:Program FilesNVIDIA GPU Computing ToolkitCUDAv12.1
CUDA_PATH_V12_1                C:Program FilesNVIDIA GPU Computing ToolkitCUDAv12.1
DevEnvDir                      C:Program FilesMicrosoft Visual Studio2022CommunityCommon7IDE
EXTERNAL_INCLUDE               C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807include
INCLUDE                        C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807include
LIB                            C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807ATLM
LIBPATH                        C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807ATLM
LIBTORCH                       "C:libtorch-win-shared-with-deps-2.3.1+cu121libtorch"
LIBTORCH_INCLUDE               "C:libtorch-win-shared-with-deps-2.3.1+cu121libtorchinclude"
LIBTORCH_LIB                   "C:libtorch-win-shared-with-deps-2.3.1+cu121libtorchlib"
OPENCV_INCLUDE_PATHS           C:opencvbuildinclude
OPENCV_LINK_LIBS               opencv_world4100.lib
OPENCV_LINK_PATHS              C:opencvbuildx64vc16lib
Path                           C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807bin...
VCPKG_ROOT                     C:Program FilesMicrosoft Visual Studio2022CommunityVCvcpkg
VCToolsInstallDir              C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.40.33807

Visual Studio 2022 Developer PowerShell v17.10.4

PS C:Usersxxxsourcerepos> cl
Microsoft(R) C/C++ Optimizing Compiler Version 19.40.33812 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Cargo.toml

[package]
name = "yolo_screen_capture_rs"
version = "0.1.0"
edition = "2021"

[dependencies]
tch = "0.5.0"
opencv = "0.92.0"

build.rs

    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:include=C:\libtorch-win-shared-with-deps-2.3.1+cu121\libtorch\include");
    println!("cargo:lib=C:\libtorch-win-shared-with-deps-2.3.1+cu121\libtorch\lib");
}

libtorch installs the following

Download here (Release version):
https://download.pytorch.org/libtorch/cu121/libtorch-win-shared-with-deps-2.3.1%2Bcu121.zip

The following is the result of a test with an appropriate cpp file to confirm that cl works and that libtorch can be included.

PS C:UsersxxxDesktop> cl -I"C:libtorch-win-shared-with-deps-2.3.1+cu121libtorchinclude" -I"C:libtorch-win-shared-with-deps-2.3.1+cu121libtorchincludetorchcsrcapiinclude" -c test.cpp
>> 
>>
Microsoft(R) C/C++ Optimizing Compiler Version 19.40.33812 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

We have re-installed the environment for c++ desktop using the visualStudio installer.

I checked the libtorch path and if the executable is actually there.

New contributor

Takumi Fukuo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật