首页 > 编程语言 >6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用

6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用

时间:2022-09-28 11:33:27浏览次数:58  
标签:人脸识别 target int C++ include ubuntu cpp libfacedetection


直接上例子:存在三个文件

 example.cpp中的文件

#include<iostream>
#include"function.h"
using namespace std;
int fun(int a,int b);
int main()
{
cout<<fun(2,3)<<endl;
cout<<"hello world"<<endl;
return 0;
}

function.cpp

#include<iostream>
#include "function.h"
int fun(int a,int b)
{
return a+b;
}

 

function.h

#include<iostream>
int fun(int a,int b);

6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用_#include

linux下用生成静态库的命令 ar 处理 function.o 文件生成静态库文件

有关详细知识可以参看官方手册,我们举个人脸的识别的例子,看如何独立编译的静态库(需要opencv支持)

ubuntu@ubuntu:~$git clone https://github.com/ShiqiYu/libfacedetection.git
ubuntu@ubuntu:~$ cd libfacedetection/
ubuntu@ubuntu:~/libfacedetection$

6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用_ubuntu_02

修改一下cmkelists.txt文件,打开demo的设置

ubuntu@ubuntu:~/libfacedetection$ mkdir -p build
ubuntu@ubuntu:~/libfacedetection$ cd build/
ubuntu@ubuntu:~/libfacedetection/build$ cmake ..
fatal: No names found, cannot describe anything.
BUILD_VERSION:v0.0.1
AVX512 = OFF
AVX2 = ON
NEON = OFF
OpenMP = TRUE
DEMO = ON
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/libfacedetection/build
ubuntu@ubuntu:~/libfacedetection/build$ make
[ 40%] Built target facedetection
[ 60%] Built target benchmark
[ 80%] Built target detect-image-demo
[100%] Built target detect-camera-demo

生成可执行文件,运行一下官方生成的可执行程序

6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用_#include_03

如果个人想把作者的工程集成到自己的项目中的话,发现作者已经提供了静态库libfacedetection.a

ubuntu@ubuntu:~/libfacedetection/example$ g++ detect-image.cpp -I ../src/ ../build/libfacedetection.a `pkg-config --cflags --libs opencv` -fopenmp -o test

6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用_静态库_04

这样基本完成了调用静态库的使用,我写了个cmakelist.txt文件进行了规整,使用Clion

代码稍微修改一下

6、C++ 静态编译链接使用库,及例子libfacedetection人脸识别应用_静态库_05

 

整个clion的目录如:(直接将libfacedetection对应的代码拷贝到新建立的文件夹即可)

ubuntu@ubuntu:~/CLionProjects$ tree
.
└── untitled
├── cmake-build-debug
├── CMakeLists.txt
├── detect-image.cpp
├── lib
│ └── libfacedetection.a
└── src
├── facedetectcnn.cpp
├── facedetectcnn.h
├── facedetectcnn-int8data.cpp
├── facedetectcnn-model.cpp
└── facedetection_export.h

15 directories, 52 files

cmakelist.txt文件内容为:

# cmake needs this line
cmake_minimum_required(VERSION 3.17)
project(opencvTest)
set( CMAKE_CXX_FLAGS "-fopenmp -O3" )
set( CMAKE_CXX_FLAGS "-fopenmp -O3" )
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/src/)
add_library(libfacedetection STATIC IMPORTED)
set_target_properties(libfacedetection PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libfacedetection.a)


# Declare the executable target built from your sources
add_executable(main detect-image.cpp)

# Link your application with OpenCV libraries
target_link_libraries(main ${OpenCV_LIBS} libfacedetection)

 

标签:人脸识别,target,int,C++,include,ubuntu,cpp,libfacedetection
From: https://blog.51cto.com/u_12504263/5719084

相关文章

  • C++ STL 概述_严丝合缝的合作者们
    1.初识STL什么是STL?STL(StandardTemplateLibrary)是C++以模板形式提供的一套标准库,提供了很多开发过程需要的通用功能模块。使用STL,可以让开发者将主要精力用于解......
  • C++ STL 概述_严丝合缝的合作者们
    1.初识STL什么是STL?STL(StandardTemplateLibrary)是C++以模板形式提供的一套标准库,提供了很多开发过程需要的通用功能模块。使用STL,可以让开发者将主要精力用于解决......
  • 实现C++智能指针
    在对象切片一文中,提到可使用充当智能指针的类shape_wrapper,可以简化资源的管理,从根本上消除资源(包括内存)泄漏的可能性,本节来看下如何将shape_wrapper改造成一个完整的智......
  • C++语言程序设计基础 内联函数
    C++内联函数是通常与类一起使用。如果一个函数是内联的,那么在编译时,编译器会把该函数的代码副本放置在每个调用该函数的地方。对内联函数进行任何修改,都需要重新编译函数......
  • C++学习之指针进阶(转载)
    1指针和数组作用:利用指针访问数组中元素示例:intarr[]={1,2,3,4,5,6,7,8,9,10};int*p=arr;//指向数组的指针cout<<"第一个元素:"<<arr[0]<<endl;......
  • C++学习 Day9-01 指针-定义及使用
    指针变量定义语法:数据类型*变量名;示例:intmain(){ //1、指针的定义 inta=10;//定义整型变量a //指针定义语法:数据类型*变量名; int*p; //指针变量......
  • C++11 获取当前时间戳
    C++11标准库chrono中包含了获取系统当前时间的工具。直接基于chrono获取,一般获取ms级的时间戳#include<chrono>longlongget_cur_time(){//获取操作系统......
  • C++ string 性能测试
    1、使用“+=”性能对比代码如下#include<stdio.h>#include<stdlib.h>#include<iostream>#include<string>#include<time.h>usingnamespacestd;intmain(......
  • 【C++】之前学习C++没有注意到的点或者学到了冷知识(待补充)
    1.string和c_str()stringstr="hello";constchar*cstr=str.c_str();str="yep,im";本来是以为str.c_str()会把str中包含的字符串在内存中开辟一个新空间存放......
  • C++模板的哲学
    2.5模板C++的模板一直是这门语言的一种特殊的艺术,模板甚至可以独立作为一门新的语言来进行使用。模板的哲学在于将一切能够在编译期处理的问题丢到编译期进行处理,仅在运......