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

Cargo build failures on LXQt #31

Open hkk97 opened 7 months ago

hkk97 commented 7 months ago

Hello, I want to try learning from this project and running the example, but I encountered a few issues. I have ensured that I have installed CMake, g++, and c++, and my versions are as follows. The build process of dlib should be without any issues, but I don't know why the wrapper.rs file is unable to link with the header files referenced from the target build folder. Could you please give me some tips or ideas on how to solve these issues?

cmake --version

$ cmake --version
cmake version 3.22.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

c++ --version

$ c++ --version
c++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ --version

$ g++ --version
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Cargo build errors

$ sudo cargo build
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /tester/dlib-face-recognition/sys/Cargo.toml
workspace: /tester/dlib-face-recognition/Cargo.toml
   Compiling dlib-face-recognition v0.3.2 (/tester/dlib-face-recognition)
The following warnings were emitted during compilation:

warning: src/wrapper.rs:2:14: fatal error: dlib/dnn.h: No such file or directory
warning:     2 |     #include <dlib/dnn.h>
warning:       |              ^~~~~~~~~~~~
warning: compilation terminated.

error: failed to run custom build command for `dlib-face-recognition v0.3.2 (/tester/dlib-face-recognition)`

Caused by:
  process didn't exit successfully: `/tester/dlib-face-recognition/target/debug/build/dlib-face-recognition-605abc5d9bdaa42a/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=./files
  cargo:rustc-link-lib=blas
  cargo:rustc-link-lib=dlib
  cargo:rustc-link-lib=lapack
  TARGET = Some("x86_64-unknown-linux-gnu")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CXX_x86_64-unknown-linux-gnu
  CXX_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CXX_x86_64_unknown_linux_gnu
  CXX_x86_64_unknown_linux_gnu = 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
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  cargo:rerun-if-env-changed=CXXFLAGS_x86_64-unknown-linux-gnu
  CXXFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CXXFLAGS_x86_64_unknown_linux_gnu
  CXXFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CXXFLAGS
  HOST_CXXFLAGS = None
  cargo:rerun-if-env-changed=CXXFLAGS
  CXXFLAGS = None
  running: "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-I" "/tester/dlib-face-recognition" "-Wall" "-Wextra" "-std=c++14" "-o" "/tester/dlib-face-recognition/target/debug/build/dlib-face-recognition-d626b80a744e4d5a/out/1050f4fc78588567-cpp_closures.o" "-c" "/tester/dlib-face-recognition/target/debug/build/dlib-face-recognition-d626b80a744e4d5a/out/rust_cpp/cpp_closures.cpp"
  cargo:warning=src/wrapper.rs:2:14: fatal error: dlib/dnn.h: No such file or directory

  cargo:warning=    2 |     #include <dlib/dnn.h>

  cargo:warning=      |              ^~~~~~~~~~~~

  cargo:warning=compilation terminated.

  exit status: 1

  --- stderr

  error occurred: ToolExecError: Command "c++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-I" "/tester/dlib-face-recognition" "-Wall" "-Wextra" "-std=c++14" "-o" "/tester/dlib-face-recognition/target/debug/build/dlib-face-recognition-d626b80a744e4d5a/out/1050f4fc78588567-cpp_closures.o" "-c" "/tester/dlib-face-recognition/target/debug/build/dlib-face-recognition-d626b80a744e4d5a/out/rust_cpp/cpp_closures.cpp" with args "c++" did not execute successfully (status code exit status: 1).
HoKim98 commented 7 months ago

Hello, this error may occur if the dlib native library is not installed on the host machine. This can be resolved by installing the library using a package manager, or preparing it for linking by manually building or downloading the binary.

If this process is cumbersome and you want to proceed smoothly, you can configure it to build automatically by activating the build-native feature when building cargo like: cargo build --features build-native.

The reason this feature is turned off by default is because the build time takes quite a bit, over 30 minutes.

hkk97 commented 7 months ago

Thank you for answering and providing the suggested ideas. I think I should try running it on macOS and Windows. To be honest, running cargo build --features build-native works fine for me. However, it seems to fail to link with the dlib library. I tried linking with the dlib library by configuring the .vscode/c_cpp_properties.json file as shown in the code below. After that, I ran cargo run again, and the built .o object file was able to link with thedlib library on my PC. However, the src/wrapper.rs file still fails to link with the header files from dlib.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/tester/Desktop/dlib"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",                     
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}
HoKim98 commented 4 months ago

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.