aarch64-linux-gnu- 交叉编译dlib库说明
1. 源码下载
下载 dlib库源码,dlib C++ Library
2. 编译安装
2.1 将 下载的源码包 dlib-19.24.zip
放入交叉编译的环境下,解压文件,并创建 build
文件夹,并创建交叉编译库的文件夹 arm_dlib
unzip dlib-19.24.zip
cd dlib-19.24
mkdir build && cd build
mkdir arm_dlib
2.1 更改CmakeLists.txt , 设置指定交叉编译器
dlib-19.24
目录下打开 CmakeLists.txt
并修改如下:
## cmakelists.txt参考如下
cmake_minimum_required(VERSION 3.10)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR aarch64)
SET(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
SET(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
project(v4l2_decode LANGUAGES CXX C)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g -Wall")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -Wall")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2 -ffunction-sections -fdata-sections")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O2 -ffunction-sections -fdata-sections")
project(dlib_project)
#############################################################################
# #
# READ examples/CMakeLists.txt TO SEE HOW TO USE DLIB FROM C++ WITH CMAKE #
# #
#############################################################################
get_directory_property(has_parent PARENT_DIRECTORY)
if(NOT has_parent)
# When you call add_subdirectory(dlib) from a parent CMake project dlib's
# CMake scripts will assume you want to statically compile dlib into
# whatever you are building rather than create a standalone copy of dlib.
# This means CMake will build dlib as a static library, disable dlib's
# install targets so they don't clutter your project, and adjust a few other
# minor things that are convenient when statically building dlib as part of
# your own projects.
#
# On the other hand, if there is no parent CMake project or if
# DLIB_IN_PROJECT_BUILD is set to false, CMake will compile dlib as a normal
# standalone library (either shared or static, based on the state of CMake's
# BUILD_SHARED_LIBS flag), and include the usual install targets so you can
# install dlib on your computer via `make install`. Since the only reason
# to build this CMakeLists.txt (the one you are reading right now) by itself
# is if you want to install dlib, we indicate as such by setting
# DLIB_IN_PROJECT_BUILD to false.
set(DLIB_IN_PROJECT_BUILD false)
endif()
add_subdirectory(dlib)
2.2 aarch64-linux-gnu- 交叉编译静态库到指定路径
可以交叉编译库文件到指定路径,在 dlib-19.24/build/
目录下,输入指令:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=./build/arm_dlib ..
make install
编译安装完成后,在 arm_dlib
目录下生成了 include
、lib
,这样交叉编译 dlib 库就完成了。
3. 引用 dlib 库
将 arm_dlib
复制到源码引用库的路径,在源码的 CmakeLists.txt
中添加 dlib
库头文件和库。更改如下:
include_directories(
../deps/arm_dlib/include
)
link_directories(
../deps/arm_dlib/lib
)
target_link_libraries(
dlib
)