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.
Takumi Fukuo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.