ulagbulag / dlib-face-recognition

Unofficial Rust wrappers to the C++ library dlib, face recognition tools
BSD 3-Clause "New" or "Revised" License
45 stars 28 forks source link

Cannot build on Tauri project #32

Closed gkhnv closed 4 months ago

gkhnv commented 4 months ago

Hello, I am currently working on a Tauri project that needs to use face recognition. I have python code for such functionality, however i need to rewrite the code in rust to make it work on my desktop app. I added the crate to the cargo.toml, I have all the mentioned prerequisites in my machine. I already installed cmake (version 3.29.2) and dlib (installed through vcpkg). When I try to build the program it gives the following error:

2024-05-06T09:57:56.219326Z ERROR rust_analyzer::main_loop: FetchBuildDataError:
The following warnings were emitted during compilation:

error: failed to run custom build command for `dlib-face-recognition v0.3.2`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-2512533d306bcbe8\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-changed=./files
  cargo:rustc-flags=-L C:\Users\vural\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dlib-face-recognition-0.3.2\external-libs\windows
  cargo:rustc-link-lib=blas
  cargo:rustc-link-lib=lapack
  cargo:rustc-link-lib=static=dlib
  TARGET = Some("x86_64-pc-windows-msvc")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-msvc")
  cargo:rerun-if-env-changed=CXX_x86_64-pc-windows-msvc
  CXX_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CXX_x86_64_pc_windows_msvc
  CXX_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=HOST_CXX
  HOST_CXX = None
  cargo:rerun-if-env-changed=CXX
  CXX = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CXXFLAGS_x86_64-pc-windows-msvc
  CXXFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CXXFLAGS_x86_64_pc_windows_msvc
  CXXFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=HOST_CXXFLAGS
  HOST_CXXFLAGS = None
  cargo:rerun-if-env-changed=CXXFLAGS
  CXXFLAGS = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:warning=cl : Command line warning D9002 : ignoring unknown option '-std=c++14'
  cpp_closures.cpp
  src\wrapper.rs(2): fatal error C1083: Cannot open include file: 'dlib/dnn.h': No such file or directory

  --- stderr

  error occurred: ToolExecError: Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "C:\\Users\\vural\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\dlib-face-recognition-0.3.2" "-W4" "-std=c++14" "-FoC:\\Users\\vural\\OneDrive\\Masaüstü\\New folder\\programming\\binance_webapp\\Zentrads v2\\src-tauri\\target\\debug\\build\\dlib-face-recognition-66c5a8f8eedbfbb1\\out\\00fe3d72988c521e-cpp_closures.o" "-c" "C:\\Users\\vural\\OneDrive\\Masaüstü\\New folder\\programming\\binance_webapp\\Zentrads v2\\src-tauri\\target\\debug\\build\\dlib-face-recognition-66c5a8f8eedbfbb1\\out\\rust_cpp\\cpp_closures.cpp" with args "cl.exe" did not execute successfully (status code exit code: 2).

However, when I try to build it using "build-native" feature, it gives the following error:

2024-05-06T10:32:15.800700Z ERROR flycheck: Flycheck failed to run the following command: CommandHandle { program: "C:\\Users\\vural\\.cargo\\bin\\cargo.exe", arguments: ["check", "--workspace", "--message-format=json-diagnostic-rendered-ansi", "--manifest-path", "C:\\Users\\path\\to\\the\\project\\src-tauri\\Cargo.toml", "--all-targets"], current_dir: Some("C:\\Users\\path\\to\\the\\project\\src-tauri") }, error=Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(ExitStatus(101))):
   Compiling dlib-face-recognition-sys v19.24.0-rc.1
error: failed to run custom build command for `dlib-face-recognition-sys v19.24.0-rc.1`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-909d0eb2232a950f\build-script-build` (exit code: 101)
  --- stdout
  CMAKE_TOOLCHAIN_FILE_x86_64-pc-windows-msvc = None
  CMAKE_TOOLCHAIN_FILE_x86_64_pc_windows_msvc = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-pc-windows-msvc = None
  CMAKE_GENERATOR_x86_64_pc_windows_msvc = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-pc-windows-msvc = None
  CMAKE_PREFIX_PATH_x86_64_pc_windows_msvc = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-pc-windows-msvc = None
  CMAKE_x86_64_pc_windows_msvc = None
  HOST_CMAKE = None
  CMAKE = None
  running: "cmake" "C:\\Users\\path\\to\\the\\project\\src-tauri\\target\\debug\\build\\dlib-face-recognition-sys-11dfa1846fdb6b9f\\out\\dlib-19.24" "-G" "Visual Studio 17 2022" "-Thost=x64" "-Ax64" "-DCMAKE_INSTALL_PREFIX=install" "-DCMAKE_C_FLAGS= -nologo -MD -Brepro" "-DCMAKE_C_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_BUILD_TYPE=Debug"
  -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
  -- Configuring incomplete, errors occurred!

  --- stderr
  Already got 'C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\dlib-19.24'
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
    Compatibility with CMake < 3.5 will be removed from a future version of
    CMake.

    Update the VERSION argument <min> value or use a ...<max> suffix to tell
    CMake that the project does not need compatibility with older versions.

  CMake Error at CMakeLists.txt:3 (project):
    Failed to run MSBuild command:

      C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe

    to get the value of VCTargetsPath:

      MSBuild version 17.9.8+b34f75857 for .NET Framework
      Build started 5/6/2024 1:32:15 PM.

      Project "C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj" on node 1 (default targets).
      PrepareForBuild:
        Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
      InitializeBuildStatus:
        Touching "VCTargetsPath\x64\Debug\VCTargetsPath.tlog\unsuccessfulbuild".
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: The "GetOutOfDateItems" task failed unexpectedly. [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: System.InvalidOperationException: The item metadata "%(FullPath)" cannot be applied to the path "VCTargetsPath\x64\Debug\VCTargetsPath.tlog\ParallelCustomBuild.command.1.tlog". Path: VCTargetsPath\x64\Debug\VCTargetsPath.tlog\ParallelCustomBuild.command.1.tlog exceeds the OS max path limit. The fully qualified file name must be less than 260 characters. [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Shared.FileUtilities.ItemSpecModifiers.GetItemSpecModifier(String currentDirectory, String itemSpec, String definingProjectEscaped, String modifier, String& fullPath) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Utilities.TaskItem.Microsoft.Build.Framework.ITaskItem2.GetMetadataValueEscaped(String metadataName) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Utilities.TaskItem.GetMetadata(String metadataName) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.CPPTasks.GetOutOfDateItems.Execute() [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      Done Building Project "C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj" (default targets) -- FAILED.

      Build FAILED.

      "C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj" (default target) (1) ->
      (CustomBuild target) -> 
        C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: The "GetOutOfDateItems" task failed unexpectedly. [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: System.InvalidOperationException: The item metadata "%(FullPath)" cannot be applied to the path "VCTargetsPath\x64\Debug\VCTargetsPath.tlog\ParallelCustomBuild.command.1.tlog". Path: VCTargetsPath\x64\Debug\VCTargetsPath.tlog\ParallelCustomBuild.command.1.tlog exceeds the OS max path limit. The fully qualified file name must be less than 260 characters. [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Shared.FileUtilities.ItemSpecModifiers.GetItemSpecModifier(String currentDirectory, String itemSpec, String definingProjectEscaped, String modifier, String& fullPath) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Utilities.TaskItem.Microsoft.Build.Framework.ITaskItem2.GetMetadataValueEscaped(String metadataName) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.Utilities.TaskItem.GetMetadata(String metadataName) [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.CPPTasks.GetOutOfDateItems.Execute() [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Users\path\to\the\project\src-tauri\target\debug\build\dlib-face-recognition-sys-11dfa1846fdb6b9f\out\build\CMakeFiles\3.29.2\VCTargetsPath.vcxproj]

          0 Warning(s)
          1 Error(s)

      Time Elapsed 00:00:00.25

    Exit code: 1

  thread 'main' panicked at C:\Users\vural\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cmake-0.1.50\src\lib.rs:1098:5:

  command did not execute successfully, got: exit code: 1

  build script failed, must exit now
  stack backtrace:
     0: std::panicking::begin_panic_handler
               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:647
     1: core::panicking::panic_fmt
               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\panicking.rs:72
     2: cmake::find_exe::{{closure}}
     3: <cmake::Version as core::default::Default>::default
     4: cmake::Config::build
     5: byteorder::io::ReadBytesExt::read_u64
     6: byteorder::io::ReadBytesExt::read_u64
     7: core::ops::function::FnOnce::call_once{{vtable.shim}}
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I would really appreciate any help. Thanks.

HoKim98 commented 4 months ago

Hi, it seems that the system library dlib you installed has not found by our build.rs. Could you register an environment variable DEP_DLIB_INCLUDE to your dlib path? It's likely be a __YOUR_LIBRARY_PATH__/dlib-19.24 if you downloaded it from the official homepage.

gkhnv commented 4 months ago

Hello, thanks for the answer. At first I installed dlib by using vcpkg. I registered that to the environment variable, yet it doesn't seem to solve the problem. Then I tried to install it from dlib's official page. I tried to include the source code path for the env variable, both root directory and the "dlib" directory inside of the "dlib-19.24" folder. None of them helps. When I downloaded the source code from the website, I wanted to compile the examples using cmake, however it still gives errors. Maybe there is some problem with my cmake installation. I downloaded the binary from the official website and followed instructions. I also installed CUDA and CUDNN into my machine.

When i try to build the dlib examples it gives this error, which I couldn't find anything from the web:

CMake Deprecation Warning at CMakeLists.txt:35 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
CMake Deprecation Warning at C:/dlib-19.24/dlib/CMakeLists.txt:2 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

CMake Error at C:/dlib-19.24/dlib/CMakeLists.txt:4 (include):
  include could not find requested file:

    ../use_cpp_11.cmake

CMake Warning (dev) at C:/dlib-19.24/dlib/CMakeLists.txt:8 (find_package):
  Policy CMP0146 is not set: The FindCUDA module is removed.  Run "cmake
  --help-policy CMP0146" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at C:/dlib-19.24/dlib/CMakeLists.txt:13 (include):
  include could not find requested file:

    find_cudnn.txt

OpenCV not found, so we won't build the webcam_face_pose_ex example.
-- Configuring incomplete, errors occurred!

Thanks for your attention in advance.

HoKim98 commented 4 months ago
  1. As I know, to apply the env settings, the machine should be rebooted.
  2. Could you share your entire environment variables? CUDA and CUDNN should also be registered on the env.
gkhnv commented 4 months ago

I have solved the problem. I was trying to install the dlib-face-recognition library into a already existing project. I don't know why, but it somehow gave the error that I mentioned in the very first comment. When I tried it with a new project it worked just fine. Thanks for your attention.