天天看點

Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

eos 是一個用現代 C++11/14 編寫的輕量級三維形變人臉模型拟合庫,下面介紹下編譯它的步驟和遇到的一些坑坑坑坑!

  • 博文的前半部分是用手動安裝的 opencv 和 boost 建構和編譯的,一路是坑,最終沒有編譯成功;
  • 博文的後半部分是用 vcpkg 建構系統安裝的 opencv 和 boost 然後建構和編譯的,最終編譯成功,但是運作失敗。

至今為止,關于運作失敗的 issue 作者也沒有回複,希望有朝一日能填坑吧~

初期編譯環境

  • Windows 10
  • Visual Studio 2017
  • CMake 3.12.4
  • OpenCV 4.0.1
  • Boost 1.66.0

克隆配置

git clone --recursive [email protected]:patrikhuber/eos.git
mkdir eos_build
           

打開 CMake-gui,設定

  • Where is the source code:

    D:/code/VS/BabyCreator/eos

  • Where to build the binaries:

    D:/code/VS/BabyCreator/eos_build

點選 Configure,設定編譯器

  • Specify the generator for this project: Visual Studio 15 2017
  • Finish

配置過程遇到如下錯誤。

Found OpenCV Windows Pack but it has no binaries compatible with your configuration. 錯誤

問題

Found OpenCV Windows Pack but it has no binaries compatible with your
  configuration.

  You should manually point CMake variable OpenCV_DIR to your build of OpenCV
  library.
           
Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

原因

能找到 OpenCV 路徑,但找不到相容的二進制檔案。

出錯的這個 OpenCV 是在 opencv.org/releases 下載下傳的 Win pack。

嘗試過網友的解決方案【嘗試二、三、四】都不能解決,最終通過【嘗試五】重新下載下傳源碼編譯解決,是以可能是建構環境或者編譯器的問題。

解決

【嘗試一】重新設定環境變量:

E:\opencv-4.0.1\opencv-4.0.1-winpack\opencv\build\x64\vc15\bin

【嘗試二】在

eos/CMakeCache.txt

設定 OpenCV_DIR,不行。

set(OpenCV_DIR "D:\\code\\VS\\BabyCreator\\eos\\3rdparty\\opencv\\build")
find_package(OpenCV REQUIRED)
           

【嘗試三】在終端設定 OpenCV_DIR,不行。

PS D:\code\VS\BabyCreator\eos> cmake . -DOpenCV_DIR=D:\\code\\VS\\BabyCreator\\eos\\3rdparty\\opencv\\build\\OpenCVConfig.cmake
           

【嘗試四】在 find_package 前設定 OpenCV_FOUND 為 1,不行。

set(OpenCV_FOUND 1)
find_package(OpenCV REQUIRED)
           

【嘗試五】下載下傳源碼編譯 VS 2017 工程的 opencv,解決。

  1. 在 CMake Configure、Generate
  2. 在 VS ALL_BUILD、INSTALL
  3. 執行

    install/setup_vars_opencv4.cmd

  4. 設定環境變量:

    E:/opencv-4.0.1/opencv-4.0.1-vs-build/install/x86/vc15/bin

Imported targets and dependency information not available for Boost version 錯誤

CMake Warning at E:/CMake/share/cmake-3.12/Modules/FindBoost.cmake:577 (message):
  Imported targets and dependency information not available for Boost version
  (all versions older than 1.33)
Call Stack (most recent call first):
  E:/CMake/share/cmake-3.12/Modules/FindBoost.cmake:963 (_Boost_COMPONENT_DEPENDENCIES)
  E:/CMake/share/cmake-3.12/Modules/FindBoost.cmake:1622 (_Boost_MISSING_DEPENDENCIES)
  examples/CMakeLists.txt:22 (find_package)
......
Boost found at Boost_INCLUDE_DIR-NOTFOUND
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
D:/code/VS/BabyCreator/eos/examples/Boost_INCLUDE_DIR
   used as include directory in directory D:/code/VS/BabyCreator/eos/examples
   used as include directory in directory D:/code/VS/BabyCreator/eos/examples
   used as include directory in directory D:/code/VS/BabyCreator/eos/examples
   used as include directory in directory D:/code/VS/BabyCreator/eos/examples

Configuring incomplete, errors occurred!
           
Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

原因

沒找到 Boost 庫,原因是沒配置好。

解決

嘗試了如下方式後,這個問題變成了

Unable to find the requested Boost libraries.

  1. 下載下傳 boost
  2. 運作

    boost_1_66_0/b2.exe

    生成靜态庫
  3. eos/CMakeCache.txt

    配置
    set(BOOST_ROOT "E:\\boost_1_66_0")
    set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib)
               

Unable to find the requested Boost libraries. 錯誤

CMake Error at E:/CMake/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.66.0

  Boost include path: E:/boost_1_66_0

  Could not find the following Boost libraries:

          boost_system
          boost_filesystem
          boost_program_options

  No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.
Call Stack (most recent call first):
  examples/CMakeLists.txt:22 (find_package)


Boost found at E:/boost_1_66_0
Configuring incomplete, errors occurred!
           
Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

原因

找到了 Boost 庫,但是找不到

boost_system

boost_filesystem

boost_program_options

這三個庫。

解決

這個問題太坑了,最終是把

E:\boost_1_66_0\stage\lib

裡面的那三個庫(每個有四個相關庫)的名字分别删掉

lib

,如下對

boost_system

的修改:

  • libboost_system-vc141-mt-x32-1_66.lib

    改為

    boost_system-vc141-mt-x32-1_66.lib

  • libboost_system-vc141-mt-gd-x32-1_66.lib

    改為

    boost_system-vc141-mt-gd-x32-1_66.lib

  • libboost_system-vc141-mt-x64-1_66.lib

    改為

    boost_system-vc141-mt-x64-1_66.lib

  • libboost_system-vc141-mt-gd-x64-1_66.lib

    改為

    boost_system-vc141-mt-gd-x64-1_66.lib

現在終于可以生成工程檔案了!

然而 VS 打開工程後編譯,又有問題。

error C2065: “CV_BGR2BGRA”: 未聲明的辨別符

generate-obj.vcxproj

eos\include\eos\render\texture.hpp(101): error C2065: “CV_BGR2BGRA”: 未聲明的辨別符 (undeclared identifier)
           

解決

這個問題可以根據這個 issue,把

CV_BGR2BGRA

改為

cv::COLOR_BGR2BGRA

,或者改為

解決。

error LNK2005: xxx 已經在 xxx 中定義;error LNK2019: 無法解析的外部符号

fit-model-simple.vcxproj

1>boost_program_options-vc140-mt-gd.lib(boost_program_options-vc141-mt-gd-x32-1_68.dll) : error LNK2005: "public: __thiscall boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper<char>(void)" ([email protected]@[email protected]@@[email protected]) 已經在 boost_program_options-vc141-mt-gd-x32-1_66.lib(value_semantic.obj) 中定義
1>boost_program_options-vc140-mt-gd.lib(boost_program_options-vc141-mt-gd-x32-1_68.dll) : error LNK2005: "public: virtual __thiscall boost::program_options::value_semantic_codecvt_helper<char>::~value_semantic_codecvt_helper<char>(void)" ([email protected]@[email protected]@@[email protected]) 已經在 boost_program_options-vc141-mt-gd-x32-1_66.lib(value_semantic.obj) 中定義
1>boost_program_options-vc140-mt-gd.lib(boost_program_options-vc141-mt-gd-x32-1_68.dll) : error LNK2005: "void __cdecl boost::program_options::validate(class boost::any &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *,int)" ([email protected][email protected]@@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) 已經在 boost_program_options-vc141-mt-gd-x32-1_66.lib(value_semantic.obj) 中定義
1>boost_program_options-vc140-mt-gd.lib(boost_program_options-vc141-mt-gd-x32-1_68.dll) : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::program_options::to_internal(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected][email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) 已經在 boost_program_options-vc141-mt-gd-x32-1_66.lib(convert.obj) 中定義
1>  正在建立庫 D:/code/VS/BabyCreator/eos_build/examples/Debug/fit-model-simple.lib 和對象 D:/code/VS/BabyCreator/eos_build/examples/Debug/fit-model-simple.exp
1>fit-model-simple.obj : error LNK2019: 無法解析的外部符号 "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" ([email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]),該符号在函數 __catch$_main$0 中被引用
1>fit-model-simple.obj : error LNK2019: 無法解析的外部符号 "bool __cdecl cv::imwrite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::debug_build_guard::_InputArray const &,class std::vector<int,class std::allocator<int> > const &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected][email protected]@[email protected]@@[email protected]@Z),該符号在函數 __catch$_main$6 中被引用
1>D:\code\VS\BabyCreator\eos_build\examples\Debug\fit-model-simple.exe : fatal error LNK1120: 2 個無法解析的外部指令
           

原因

這個問題可能是安裝的這個版本的 boost 庫與什麼東西不相容吧,又是環境問題,我已經無力吐槽 Windows 了(心累)。

解決

這個問題我在官方倉庫提了個 issue。

作者的意思是:我沒試過你的 boost 和 opencv 的版本,可能是本地配置問題,建議用建構系統(如 vcpkg) 或者在 StackOverflow 上提問。

我:emmm…

是以,這個問題未解決,最後是用 vcpkg 安裝庫解決的。

再次編譯環境

  • Windows 10
  • Visual Studio 2017
  • CMake 3.12.4
  • OpenCV 3.4.3
  • Boost 1.68.0
  • vcpkg 2018.11.23-nohash

vcpkg 配置安裝

安裝 vcpkg、opencv、boost

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg install opencv boost
           

安裝完成後,在

eos

同級目錄下建立 build 檔案夾

eos_vcpkg_build

,如下目錄結構:

- eos
  - CMakeLists.txt
  - ...
- eos_vcpkg_build
  - install
  - eos.sln
  - ...
           

然後執行下面的指令建構工程:

mkdir eos_vcpkg_build
cd eos_vcpkg_build
cmake ../eos -DOpenCV_DIR=D:\\code\\git\\vcpkg\\buildtrees\\opencv\\x86-windows-rel -DBOOST_ROOT=D:\\code\\git\\vcpkg\\installed\\x86-windows\\bin -DBOOST_LIBRARYDIR=D:\\code\\git\\vcpkg\\installed\\x86-windows\\bin -DBOOST_INCLUDEDIR=D:\\code\\git\\vcpkg\\installed\\x86-windows\\include -DCMAKE_INSTALL_PREFIX=install/
           
  • OpenCV_DIR

    設為 vcpkg 安裝的

    opencv 路徑

  • BOOST_ROOT

    設為 vcpkg 安裝的

    boost 路徑

  • BOOST_LIBRARYDIR

    設為 vcpkg 安裝的

    boost 庫檔案路徑

  • BOOST_INCLUDEDIR

    設為 vcpkg 安裝的

    boost 頭檔案路徑

  • CMAKE_INSTALL_PREFIX

    即為

    make install 的路徑

建構好後,用 VS 打開,右鍵

解決方案 eos

-

生成解決方案

然後選擇

INSTALL

工程 - 右鍵

設為啟動項目

- 右鍵

生成

居然成功編譯并安裝好了(喜極而泣)!

eos 運作示例

運作下

eos_vcpkg_build\install\bin\fit-model.exe

示例程式吧 ~

根據墨菲定律,必定沒這麼順利,果然…

一連跳幾個框,

由于找不到 opencv_core343.dll、opencv_imgcodecs343.dll、boost_filesystem-vc141-mt-x32-1_68.dll、jpeg62.dll、zlib1.dll 等,無法繼續執行代碼。重新安裝重新可能會解決此問題。
           
Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

既然缺少動态庫,那就去 vcpkg 安裝路徑下找,如果沒有則用 vcpkg 安裝,然後把這些 dll 放到

fit-model.exe

同級目錄下。

Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

然後就…

應用程式無法正常啟動(0xc000007b)。請點選“确定”關閉應用程式。
           
Windows 下源碼編譯 eos 人臉模型拟合庫過程遇到的坑坑坑

我:emmm…mmp

應該是動态庫的連結錯誤,關于這個問題我再次開了 issue,但是作者不再回應了。

是以,在 Windows 上,隻是編譯成功庫,但是示例都無法運作。

最終,在 Ubuntu 上,編譯運作起來了。

心累。

繼續閱讀