硬件:zlg的板卡: EPC-6708T-L (M6708Q-1Gl) 飞思卡尔,4核A9
软件:tengine1.6版本
编译链:arm-poky-linux-gnueabi
tengine的代码:https://github.com/OAID/Tengine
编译链的下载:https://www.zlg.cn/ipc/down/down/id/89.html
如上链接下载完交叉编译链之后,按照如下步骤安装:
chmod +x poky-glibc-x86_64-meta-toolchain-qt5-cortexa9hf-vfp-neon-toolchain-1.7.sh
./poky-glibc-x86_64-meta-toolchain-qt5-cortexa9hf-vfp-neon-toolchain-1.7.sh
运行
source /opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
如上已经安装完毕,以下后缀可调用到编译器 :
arm-poky-linux-gnueabi-
makefile.config中修改:
CROSS_COMPILE=arm-poky-linux-gnueabi-
EBEDDED_CROSS_ROOT=/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi #可加可不加,后面没用到
CONFIG_ARCH_ARM32=y
Makefile文件文件中修改:去掉如下内容,只留下LD
+#ifeq ($(EMBEDDED_CROSS_ROOT),)
+# CC=$(CROSS_COMPILE)gcc -std=gnu99 $(SYSROOT_FLAGS)
+# CXX=$(CROSS_COMPILE)g++ -std=c++11 $(SYSROOT_FLAGS)
+# LD=$(CROSS_COMPILE)g++ $(SYSROOT_FLAGS) $(SYSROOT_LDFLAGS)
+#else
+# CC=$(CROSS_COMPILE)gcc -std=gnu99
+# CXX=$(CROSS_COMPILE)g++ -std=c++11
+LD=$(CROSS_COMPILE)g++
+# PKG_CONFIG_PATH:=$(EMBEDDED_CROSS_ROOT)/usr/lib/pkgconfig
+#endif
然后就可以进行编译了,但是注意编译的时候还是有些坑的
错误:/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory
# include
修改:
修改environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
export CXX="arm-poky-linux-gnueabi-g++ -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT -std=c++11"
去掉Makefile中的CC和CXX等和environment中重复定义的
错误:
/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.1/bits/stl_algobase.h: In instantiation of 'const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = __builtin_neon_sf]':
./include/pooling_kernel.h:92:53: required from here
/opt/poky/1.7/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.1/bits/stl_algobase.h:217:5: internal compiler error: in write_builtin_type, at cp/mangle.c:2307
max(const _Tp& __a, const _Tp& __b)
^
Please submit a full bug report,
修改:将所有的std::max改为自定义的宏
executor/operator/arm32/include/pooling_kernel.h
executor/operator/arm32/include/pooling_kernel_int8.h
+#define MAX(a,b) ((a)>(b)?(a):(b))
+#define MIN(a,b) ((a)>(b)?(b):(a))
sed -i 's/std::max/MAX/g' ./executor/operator/arm32/include/pooling_kernel.h
sed -i 's/std::max/MAX/g' ./executor/operator/arm32/include/pooling_kernel_int8.h
错误:
arm-poky-linux-gnueabi-ld: unrecognized option '-Wl,-Bsymbolic'
arm-poky-linux-gnueabi-ld: use the --help option for usage information
arm-poky-linux-gnueabi-ld: unrecognized option '-Wl,-rpath,$ORIGIN'
arm-poky-linux-gnueabi-ld: use the --help option for usage information
根据编译器的支持
修改为如下内容: 如果出现如下错误,那么肯定是Makefile中的LD被修改为了ld,实际上Makefile的LD是g++
LD=$(CROSS_COMPILE)g++
修改:需要在test/makefile 和 internel/makefile目录下更改添加对opencv和Protobuf的目录依赖:
两种方式,一是直接添加库
直接添加库:LIBS+=$(PROTOBUF_LIB)
二是添加库目录
LIBS+= -L$(OPENCV_LIB_DIR)
添加库目录之后需要用-l指定库的名称:例如对opencv的库:
-lpthread -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
错误:
/mnt/d/Project/Tengine-D/Custom_Data/zlg/tengine/build/internal/bin/classification.o: In function `String':
/mnt/d/Project/Tengine-D/Custom_Data/zlg/tengine/3rdparty/opencv-3.2.0/include/opencv2/core/cvstd.hpp:622: undefined reference to `cv::String::allocate(unsigned int)'
/mnt/d/Project/Tengine-D/Custom_Data/zlg/tengine/build/internal/bin/classification.o: In function `get_input_data(char const*, float*, int, int, float const*, float)':
/mnt/d/Project/Tengine-D/Custom_Data/zlg/tengine/internal/bin/classification.cpp:62: undefined reference to `cv::imread(cv::String const&, int)'
/mnt/d/Project/Tengine-D/Custom_Data/zlg/tengine/build/internal/bin/classification.o: In function `~String':
修改:需要添加对库的依赖:只添加-I的目录是不够的
LIBS+=-ldl -lpthread -lresolv -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
./autogen.sh 修改 :去掉Google的链接,替换如下
curl $curlopts -L -o gmock-1.7.0.zip https://github.com/peter-wangxu/gmock/archive/1.7.0.zip
./autogen.sh
然后执行如下脚本编译:
#/bin/bash
cross_tool=arm-poky-linux-gnueabi
#cross_tool=arm-himix200-linux
CFLAGS="-fPIC" CPPFLAGS="-fPIC" ./configure --with-protoc=protoc prefix=/mnt/d/Project/Tengine-D/Custom_Data/zlg/tengine/3rdparty/protobuf/install --host=${cross_tool}
make -j4
make install
安装完成之后需要加到Tengine的编译框架中,需要做如下修改,在顶层Makefile中
PROTOBUF_CFLAGS=$(shell pwd)/3rdparty/protobuf/install/include/
PROTOBUF_LIB=$(shell pwd)/3rdparty/protobuf/install/lib/libprotobuf.so.10.0.0
COMMON_CFLAGS+=-Wno-ignored-attributes -Werror -g -I$(PROTOBUF_CFLAGS)