海思交叉编译Dlib

@海思交叉编译Dlib

一、dlib源码和交叉编译工具

dlib c++ 版本下载地址:dlib c++ 下载地址
海思交叉编译器:本文使用 arm-hisiv300-linux-gcc arm-hisiv300-linux-g++
本文使用ubuntu系统,需要按照cmake-gui:
在ubuntu终端使用命令:sudo apt-get install cmake-qt-gui
在ubuntu终端运行cmake-gui命令:cmake-gui

二、交叉编译dlib库

2.1、下载后dlib解压,并新建一个文件夹build

新建build文件夹

2.2、打开cmake-gui

在这里插入图片描述
在这里插入图片描述
将下图中标记0N 改为 OFF ,避免后面编译示例程序出错。
在这里插入图片描述

2.3、终端执行编译make ; sudo make install

2.3.1、编译错误1:

在build目录下执行make命令后,出现第一个错误
在这里插入图片描述
解决办法:在dlib-19.13目录下,打开CMakeLists.txt,添加add_compile_options(-D_GLIBCXX_USE_C99)
在这里插入图片描述

2.3.2、编译出错2:

‘round’不是‘std’的成员
解决办法:在dlib/geometry/rectangle.h 添加下图标记代码

namespace std
{
    double round(double f);
    float erfc(float f);
}

在这里插入图片描述

2.3.3、编译错误3:

error: no type named ‘exception_ptr’ in namespace ‘std’; did you mean ‘exception’?
解决办法:找到文件atomic_lockfree_defines.h
例如我的文件在:/opt/hisi-linux/x86-arm/arm-hisiv300-linux/arm-hisiv300-linux-uclibcgnueabi/include/c++/4.8.3/bits/atomic_lockfree_defines.h
在atomic_lockfree_defines.h内找到代码段

#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE

改为

#define ATOMIC_INT_LOCK_FREE 2

3.4、目前我编译只遇到以上问题,make编译完成后,执行sudo make install

三、交叉编译示例程序

3.1、新建示例程序

新建test文件,将dlib-19.13/examples/dnn_face_recognition_ex.cpp复制到test文件下。
创建文件:CMakeLists.txt

cmake_minimum_required(VERSION 2.8.4) 

PROJECT(dnn_face_recognition_ex) 


add_compile_options(-D_GLIBCXX_USE_C99)

find_package(dlib REQUIRED)

include_directories(${dlib_INCLUDE_DIRS})

ADD_EXECUTABLE(dnn_face_recognition_ex dnn_face_recognition_ex.cpp) 
TARGET_LINK_LIBRARIES(dnn_face_recognition_ex ${dlib_LIBS})

3.2、编译示例程序

终端在test目录下执行命令:

cmake . -DCMAKE_CXX_COMPILER:FILEPATH=arm-hisiv300-linux-g++ -DCMAKE_C_COMPILER:FILEPATH=arm-hisiv300-linux-gcc
make

3.3、编译出错以及解决办法

3.3.1、编译错误1:

错误: #error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code.  Turn DLIB_NO_GUI_SUPPORT off if you want to use it."

解决办法:打开文件dlib/gui_core/gui_core_kernel_2.h,注释如下图2行代码
在这里插入图片描述
注释后,需要重新编译。

3.3.2、编译错误2:

错误 对‘std::__exception_ptr::exception_ptr::exception_ptr(std::__exception_ptr::exception_ptr const&)’未定义的引用

打开文件:/usr/local/include/dlib/threads/thread_pool_extension_abstract.h 此地址是sudo make install后的地址,添加如下代码:

#include <exception>
namespace std
{
    namespace __exception_ptr
    {
        exception_ptr::exception_ptr()
            :_M_exception_object(0)
        {}
        exception_ptr::~exception_ptr()
        {}
        exception_ptr::exception_ptr(const exception_ptr& e)
            :_M_exception_object(e._M_exception_object)
        {}
        exception_ptr& exception_ptr::operator=(const exception_ptr& e)
        {
            _M_exception_object = e._M_exception_object;
            return *this;
        }
        void exception_ptr::swap(exception_ptr& e)
        {
            void* tmp = _M_exception_object;
            _M_exception_object = e._M_exception_object;
            e._M_exception_object = tmp;
        }
    }

    //__thread exception_ptr g_cur_e;
    exception_ptr current_exception()
    {
        return exception_ptr();
    }
    void rethrow_exception(exception_ptr e)
    {
        throw std::exception();
    }
}

本文是我自己编译过程遇到问题,如有错误请提示!

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值