1. android studio
  • ndk

    1. export ANDROID_NDK=/home/cxg/android/ndk/android-ndk-r10e
    2. export PATH=$ANDROID_NDK:$PATH

    版本: ndk-build -v

  • sdk

  • jdk
  1. MNN 编译步骤

https://blog.csdn.net/jacke121/article/details/106260920

  1. 1. https://developer.android.com/ndk/downloads/下载安装NDK,建议使用最新稳定版本
  2. 2. .bashrc 或者 .bash_profile 中设置 NDK 环境变量,例如:export ANDROID_NDK=/Users/username/path/to/android-ndk-r17c
  3. 3. cd /path/to/MNN
  4. 4. ./schema/generate.sh
  5. 5. ./tools/script/get_model.sh(可选,模型仅demo工程需要)
  6. 6. cd project/android
  7. MNN-master/project/android
  8. 7. 编译armv7动态库:mkdir build_32 && cd build_32 && ../build_32.sh
  9. 8. 编译armv8动态库:mkdir build_64 && cd build_64 && ../build_64.sh
  10. 9.Ubuntu mkdir build && cd build && cmake .. && make -
  11. 10scripts
  12. MNN-master/ciscripts/
  13. ├── Android
  14. ├── build.sh
  15. ├── iOS
  16. ├── Linux
  17. ├── macOS
  18. ├── parse_options.sh
  19. └── Windows
  • xargs: ../../3rd_party/flatbuffers/tmp/flatc: 没有那个文件或目录 ``` sudo apt install cmake
  1. - 安装protobuf(3.0以上) (Protocol Buffers - Google's data interchange format)

sudo apt-get install autoconf automake libtool curl make g++ unzip

git clone https://github.com/protocolbuffers/protobuf.git cd protobuf git submodule update —init —recursive ./autogen.sh

./configure CFLAGS=”-fPIC” CXXFLAGS=”-fPIC” make make check sudo make install sudo ldconfig

  1. - 问题1
  2. /usr/bin/ld: /usr/local/lib/libprotobuf.a(arena.o): relocation R_X86_64_TPOFF32 against symbol `_ZN6google8protobuf5Arena13thread_cache_E’ can not be used when making a shared object; recompile with -fPIC<br />出现原因:<br />原因是我用了protobuf的默认编译安装方式安装的,也即是autogen.sh、confiure、make && make install的步骤,如此生成的静态库libprotobuf.a不是PIC object,所以不能被其它动态库使用(因64位的so必须使用-fPIC编译选项,所有要求所链接的静态库也必须是带-fPIC编译)。<br />解决方案:<br />重新编译安装,confiure步骤时加上两个变量参数:

./configure CFLAGS=”-fPIC” CXXFLAGS=”-fPIC”

  1. 解决该问题,需要重新编译google protobuff库,并添加编译选项:-fPIC<br />以文本形式打开google buff代码目录下的configure文件,在把第25752578行修改为如下:<br />if test "x${ac_cv_env_CFLAGS_set}" = "x"; then : CFLAGS="-fPIC" fi if test "x${ac_cv_env_CXXFLAGS_set}" = "x"; then : CXXFLAGS="-fPIC"<br />需要注意的是不同版本的configure文件不同,所以源代码的行数也不同,2.3.01962行开始,贴出被替换代码,以便于替换
  2. - 问题2
  3. /usr/local/lib/libprotobuf.a(descriptor.o): relocation R_X86_64_PC32 against symbol `_ZZN6google8protobuf8internal16OnShutdownDeleteINS0_25EncodedDescriptorDatabaseEEEPT_S5_ENUlPKvE_4_FUNES7_' can not be used when making a shared object; recompile with -fPIC
  4. - 问题 3
  5. 无官影响
  6. Making check in .<br />make[1]: 进入目录“/media/wwf/data/ubuntuSoft/protobuf”<br />make check-local<br />make[2]: 进入目录“/media/wwf/data/ubuntuSoft/protobuf”<br />Making lib/libgmock.a lib/libgmock_main.a in gmock<br />/bin/bash: 第 0 行: cd: third_party/googletest/googletest: 没有那个文件或目录<br />make[2]: *** [Makefile:2302:check-local] 错误 1<br />make[2]: 离开目录“/media/wwf/data/ubuntuSoft/protobuf”<br />make[1]: *** [Makefile:2163:check-am] 错误 2<br />make[1]: 离开目录“/media/wwf/data/ubuntuSoft/protobuf”<br />make: *** [Makefile:1872:check-recursive] 错误 1
  7. <a name="gppVF"></a>
  8. # error
  9. <a name="RGbrw"></a>
  10. ## 1 缺少ndk 环境
  11. CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):<br /> Could not find toolchain file: /build/cmake/android.toolchain.cmake<br />Call Stack (most recent call first):<br /> CMakeLists.txt:30 (project)
  12. CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.<br />CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage<br />CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage<br />CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage<br />-- Configuring incomplete, errors occurred!
  13. <a name="bujS6"></a>
  14. # ubuntu
  15. [https://www.yuque.com/mnn/cn/cmake_opts](https://www.yuque.com/mnn/cn/cmake_opts)
  16. <a name="Bwb9r"></a>
  17. ## cpu

mkdir build && cd build cmake .. make -j8

  1. <a name="j6lWh"></a>
  2. ## opencl

mkdir build_opencl && cd build_opencl cmake .. -D MNN_OPENCL=ON cmake -j8 make -j8

```bash
#!/bin/bash
cmake ../../../ \
-DMNN_OPENCL=ON \
-DMNN_USE_SYSTEM_LIB=ON  \
-DMNN_SEP_BUILD=OFF  \
-DMNN_BUILD_BENCHMARK=true

cmake

cmake_minimum_required(VERSION 3.0) # 设置cmake版本
project(run) # 设置工程名字
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "   LD_LIBRARY_PATH  path: ${LD_LIBRARY_PATH}")
set(MNN_DIR /path/to/MNN-master/project/ubuntu20/build_opencl )
set(MNN_ROOT /path/to/MNN-master/include )
include_directories(${MNN_ROOT})
set(OpenCV_DIR /path/to/opencv-4.3.0/static_release ) #你之前源码包里的build文件夹,防止版本冲突
find_package(OpenCV 4 REQUIRED) #寻找这个包 opencv 包名 4 最低版本号 REQUIRED 如果没找到就报错
# find_package( MNN REQUIRED )
add_executable(${PROJECT_NAME} main.cpp ) #生成可执行文件

#target_link_libraries(${PROJECT_NAME}   ${OpenCV_LIBS} -lrt -lpthread  -lstdc++ -ldl  )
target_link_libraries(${PROJECT_NAME}   ${OpenCV_LIBS} -lrt -ldl  )
# target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}  )
target_link_libraries( ${PROJECT_NAME}  ${MNN_DIR}/libMNN.so )

android

pwd
cmake ../../../ \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI="arm64-v8a" \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_STL=c++_static \
-DANDROID_NATIVE_API_LEVEL=android-14  \
-DANDROID_TOOLCHAIN=clang \
-DMNN_OPENGL=OFF \
-DMNN_OPENCL=OFF \
-DMNN_VULKAN=ON \
-DMNN_BUILD_FOR_ANDROID_COMMAND=true \
-DMNN_USE_SYSTEM_LIB=False \
-DMNN_ARM82=ON \
-DNATIVE_LIBRARY_OUTPUT=. -DNATIVE_INCLUDE_OUTPUT=. $1 $2

make -j4