【ncnn android】算法移植(四)——ubuntu上搭建环境,测试

【ncnn android】算法移植(四)——ubuntu上搭建环境,测试,第1张

概述1.安装protobuf链接:https://blog.csdn.net/u010918487/article/details/82947157https://blog.csdn.net/kdchxue/article/details/810461922.编译ncnn$cd<ncnn-root-dir>$mkdir-pbuild$cdbuild#cmakeoptionNCNN_VULKANforenablingvulkan$cmake 1. 安装protobuf

链接:

https://blog.csdn.net/u010918487/article/details/82947157https://blog.csdn.net/kdchxue/article/details/810461922. 编译ncnn
$ cd <ncnn-root-dir>$ mkdir -p build$ cd build# cmake option NCNN_VulKAN for enabling vulkan$ cmake -DNCNN_VulKAN=OFF ..$ make -j4$ make install

报错

In file included from /usr/local/include/Google/protobuf/arena.h:48:0,                 from /usr/local/include/Google/protobuf/message.h:118,                 from /usr/local/include/Google/protobuf/text_format.h:48,                 from /home/yangna/chenjun/ncnn/ncnn-20180704/tools/caffe/caffe2ncnn.cpp:26:/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line/usr/include/c++/5/typeinfo:39:37: error: expected unqualifIEd-ID before end of line/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line/usr/include/c++/5/typeinfo:39:37: error: expected declaration before end of linetools/caffe/CMakefiles/caffe2ncnn.dir/build.make:70: recipe for target 'tools/caffe/CMakefiles/caffe2ncnn.dir/caffe2ncnn.cpp.o' Failedmake[2]: *** [tools/caffe/CMakefiles/caffe2ncnn.dir/caffe2ncnn.cpp.o] Error 1CMakefiles/Makefile2:203: recipe for target 'tools/caffe/CMakefiles/caffe2ncnn.dir/all' Failedmake[1]: *** [tools/caffe/CMakefiles/caffe2ncnn.dir/all] Error 2Makefile:127: recipe for target 'all' Failedmake: *** [all] Error 2

解决方案:

在cmakeList.txt中加一句add_deFinitions(-std=c++11)参考https://www.jianshu.com/p/988499c72b5e,加一句:set(CMAKE_CXX_FLAGS "-std=c++11")

结果
会在build文件夹下有install/includeinstall/lib两个文件夹,include是*.h头文件;lib是动态链接库。

3. 使用ncnn这里以cmakeList.txt为例。需要在cmakeList.txt中包含<ncnn project path>/build/install/include的文件夹,引入libncnn.a库文件。
cmakeList.txt的关键部分
1. include_directorIEs(/home/yangna/chenjun/ncnn/ncnn-20180704/build/install/include)					# 包含头文件2. # 项目中添加libncnn.a库add_library( libncnn STATIC importED )set_target_propertIEs(        libncnn        PROPERTIES importED_LOCATION        ${DIR}/lib/libncnn.a)3. 链接target_link_librarIEs(demo                       libncnn                      ${OpenCV_liBS}					  )
这里用centerface做测试。项目中已经有ncnn模型和相关代码。只需要编译通过就行。修改cmakeList.txt,只需要修改一处
#1.cmake versoncmake_minimum_required(VERSION 2.8)# 设置变量set (DIR /home/yangna/chenjun/ncnn/ncnn-20180704/build/install)			# 只需要修改这一处#2.project nameproject(demo C CXX)#opencvfind_package(OpenCV required)#3.set environment variableset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")#4. includeinclude_directorIEs(${DIR}/include                    ${CMAKE_CURRENT_List_DIR}/cpp)# ncnn libadd_library( libncnn STATIC importED )set_target_propertIEs(        libncnn        PROPERTIES importED_LOCATION        ${DIR}/lib/libncnn.a)# add OPENMP support FIND_PACKAGE( OpenMP required)if(OPENMP_FOUND)message("OPENMP FOUND")set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")set(CMAKE_EXE_linkER_FLAGS "${CMAKE_EXE_linkER_FLAGS} ${OpenMP_EXE_linkER_FLAGS}")endif()#6.source directoryfile(GLOB TEST_SRC ${CMAKE_CURRENT_List_DIR}/cpp/*.cpp                   ${CMAKE_CURRENT_List_DIR}/demo.cpp)set(TEST_COMPILE_CODE ${TEST_SRC})add_executable(demo ${TEST_COMPILE_CODE})target_link_librarIEs(demo                       libncnn                      ${OpenCV_liBS}					  )
编译项目
cd $projectmakedir buildcmake ..make
执行
./demo 
结果

总结

以上是内存溢出为你收集整理的【ncnn android】算法移植(四)——ubuntu上搭建环境,测试全部内容,希望文章能够帮你解决【ncnn android】算法移植(四)——ubuntu上搭建环境,测试所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1060889.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存