NCNN在linux环境中的安装编译(Build for Linux)

时间:2019-02-25
本文章向大家介绍NCNN在linux环境中的安装编译(Build for Linux),主要包括NCNN在linux环境中的安装编译(Build for Linux)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

官方的编译过程参考为:NCNN在linux的配置编译官方参考

下载NCNN工程:

$ git clone https://github.com/Tencent/ncnn

在安装编译前需要安装g++ cmake protobuf等工具;

然后安装编译工程。

$cd ncnn
$mkdir build && cd build
$cmake .. 

此时如果报:

/usr/local/bin/protoc: error while loading shared libraries: libprotobuf.so.15: cannot open shared object file: No such file or directory CMake Warning at /usr/local/share/cmake-3.6/Modules/FindProtobuf.cmake:387 (message):   Protobuf compiler version doesn't match library version 3.5.0

(参考:https://blog.csdn.net/stevenluopan/article/details/44746193)

就是说protobuf编译器版本与库版本不匹配。解决方法如下:

此时需要在root权限下执行如下:

[root@localhost chensq]# vim /etc/ld.so.conf

加入: /usr/local/lib

之后

[root@localhost chensq]# ldconfig

[root@localhost chensq]# export LD_LIBRARY_PATH=/usr/local/lib

这样之后重新进行cmake ..将不会报错;

[root@localhost ncnn]# rm -rf build

[root@localhost ncnn]# mkdir build

[root@localhost ncnn]# cd build/

[root@localhost build]# cmake ..

-- CMAKE_INSTALL_PREFIX = /home/chensq/ncnn/build/install

-- The C compiler identification is GNU 4.8.5

-- The CXX compiler identification is GNU 4.8.5

-- Check for working C compiler: /bin/cc

-- Check for working C compiler: /bin/cc -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Detecting C compile features

-- Detecting C compile features - done

-- Check for working CXX compiler: /bin/c++

-- Check for working CXX compiler: /bin/c++ -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Detecting CXX compile features

-- Detecting CXX compile features - done

-- Try OpenMP C flag = [-fopenmp]

-- Performing Test OpenMP_FLAG_DETECTED

-- Performing Test OpenMP_FLAG_DETECTED - Success

-- Try OpenMP CXX flag = [-fopenmp]

-- Performing Test OpenMP_FLAG_DETECTED

-- Performing Test OpenMP_FLAG_DETECTED - Success

-- Found OpenMP: -fopenmp 

-- Looking for pthread.h

-- Looking for pthread.h - found

-- Looking for pthread_create

-- Looking for pthread_create - not found

-- Looking for pthread_create in pthreads

-- Looking for pthread_create in pthreads - not found

-- Looking for pthread_create in pthread

-- Looking for pthread_create in pthread - found

-- Found Threads: TRUE 

-- Found Protobuf: /usr/local/lib/libprotobuf.so;-lpthread (found version "3.5.0")

-- Configuring done

-- Generating done

-- Build files have been written to: /home/chensq/ncnn/build

然后执行

[root@localhost build]# make -j4

会生成如下几个可执行文件