dlib交叉編譯到arm

dlib交叉編譯到arm

使用dlib是很方便的,開發者可以將其視爲一個工具來使用,看其說明:

High Quality Portable Code
Good unit test coverage. The ratio of unit test lines of code to library lines of code is about 1 to 4.
The library is tested regularly on MS Windows, Linux, and Mac OS X systems. However, it should work on any POSIX system and has been used on Solaris, HPUX, and the BSDs.
No other packages are required to use the library. Only APIs that are provided by an out of the box OS are needed. 
There is no installation or configure step needed before you can use the library. See the How to compile page for details.
All operating system specific code is isolated inside the OS abstraction layers which are kept as small as possible. The rest of the library is either layered on top of the OS abstraction layers or is pure ISO standard C++.

看這一句:

There is no installation or configure step needed before you can use the library. See the How to compile page for details.

所以,根據dlib寫的代碼,一般直接靜態鏈接到dlib的靜態庫,而編譯dlib的靜態庫也很簡單,一個cmake就可以了。由此可見,這裏很方便。

這裏簡單記錄交叉編譯example的過程。
1、增加交叉編譯配置文件
這個在之前opencv以前說過了,也是照抄即可
2、編輯example的CMakeLists.txt
編輯之前是這樣的:


  cmake_minimum_required(VERSION 2.8.4)

  PROJECT(examples)

  include(../dlib/cmake)
...

編輯爲:


   include(./toolchainfile.cmake)
   set(pthreadlib /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/a7_softfp_neon-vfpv4/libpthread.so.0)

   cmake_minimum_required(VERSION 2.8.4)

  PROJECT(examples)

  include(../dlib/cmake)

除了增加了一個交叉編譯的設定文件外,還增加了一個pthreadlib的路徑。這個是因爲需要編譯dlib的時候需要依賴這個庫。

因爲板子上沒有窗口相關的庫,所以,不能使用那些用到了x11的接口。

而直接使用g++編譯也很簡單,如(在example目錄):
arm-hisiv300-linux-g++ -O3 -I.. ../dlib/all/source.cpp -lpthread timer_ex.cpp -DDLIB_NO_GUI_SUPPORT=1

那個source.cpp就是dlib的所有了,通過各中宏來控制選擇各種特性。

發佈了111 篇原創文章 · 獲贊 46 · 訪問量 36萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章