0%

D3:MNN和OpenCV编译

踩了两个坑,一个是MNN的交叉编译,一个是OpenCV的编译。编译方法都很直接,主要记录一下坑吧。

D3: MNN和OpenCV编译

1. MNN的交叉编译

其实直接参照MNN文档的示例,就可以编译完成。

1
2
3
4
5
6
7
8
9
export cross_compile_toolchain=linaro/aarch64
mkdir build && cd build
cmake .. \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_VERSION=1 \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DCMAKE_C_COMPILER=$cross_compile_toolchain/bin/aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=$cross_compile_toolchain/bin/aarch64-linux-gnu-g++
make -j4

最开始编译的时候遇到了一个类型转换的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[ 36%] Built target MNNTransform
[ 36%] Built target MNNUtils
[ 36%] Building CXX object CMakeFiles/MNNCPU.dir/source/backend/cpu/compute/WinogradInt8Helper.cpp.o
/data/mnn/source/backend/cpu/compute/WinogradInt8Helper.cpp: In function 'void MNN::TRANS_4x4(MNN::VecType&, MNN::VecType&, MNN::VecType&, MNN::VecType&)':
/data/mnn/source/backend/cpu/compute/WinogradInt8Helper.cpp:39:48: note: use -flax-vector-conversions to permit conversions between vectors with differing element types or numbers of subparts
auto m0 = vtrn1q_s32(vec0.value, vec1.value), m1 = vtrn2q_s32(vec0.value, vec1.value);
^
/data/mnn/source/backend/cpu/compute/WinogradInt8Helper.cpp:39:48: error: cannot convert 'int8x16_t {aka __vector(16) signed char}' to 'int32x4_t {aka __vector(4) int}' for argument '1' to 'int32x4_t vtrn1q_s32(int32x4_t, int32x4_t)'
/data/mnn/source/backend/cpu/compute/WinogradInt8Helper.cpp:40:48: error: cannot convert 'int8x16_t {aka __vector(16) signed char}' to 'int32x4_t {aka __vector(4) int}' for argument '1' to 'int32x4_t vtrn1q_s32(int32x4_t, int32x4_t)'
auto m2 = vtrn1q_s32(vec2.value, vec3.value), m3 = vtrn2q_s32(vec2.value, vec3.value);
^
/data/mnn/source/backend/cpu/compute/WinogradInt8Helper.cpp:42:29: error: 'm1' was not declared in this scope
vec1.value = vtrn1q_s64(m1, m3);
^~
/data/mnn/source/backend/cpu/compute/WinogradInt8Helper.cpp:42:33: error: 'm3' was not declared in this scope
vec1.value = vtrn1q_s64(m1, m3);
^~
CMakeFiles/MNNCPU.dir/build.make:2054: recipe for target 'CMakeFiles/MNNCPU.dir/source/backend/cpu/compute/WinogradInt8Helper.cpp.o' failed
make[2]: *** [CMakeFiles/MNNCPU.dir/source/backend/cpu/compute/WinogradInt8Helper.cpp.o] Error 1
CMakeFiles/Makefile2:141: recipe for target 'CMakeFiles/MNNCPU.dir/all' failed
make[1]: *** [CMakeFiles/MNNCPU.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

参考官方github上的#1560即可解决。

2. OpenCV编译

其实没啥好说的,主要是有些组件需要在线拉取,国内这个网络环境实在是令人无语,花了几个美元租了国外的云服务,直接编译就可以。编译方法参考官方教程即可。