编译脚本如下:
export CC=${OHOS_TOOLCHAIN}/bin/clang
export CXX=${OHOS_TOOLCHAIN}/bin/clang++
export AR=${OHOS_TOOLCHAIN}/bin/llvm-ar
export AS=${OHOS_TOOLCHAIN}/bin/llvm-as
export NM=${OHOS_TOOLCHAIN}/bin/llvm-nm
export STRIP=${OHOS_TOOLCHAIN}/bin/llvm-strip
export RANLIB=${OHOS_TOOLCHAIN}/bin/llvm-ranlib
export LD=${OHOS_TOOLCHAIN}/bin/ld.lld
#export LDFLAGS="--rtlib=compiler-rt -fuse-ld=lld"
export LDFLAGS="--rtlib=compiler-rt -L${OHOS_TOOLCHAIN}/lib -lc++ -fuse-ld=lld"
export CFLAGS="-fPIC --target=aarch64-linux-ohos -march=armv8-a -isystem ${OHOS_TOOLCHAIN}/include"
export CPPFLAGS="-fPIC --target=aarch64-linux-ohos -march=armv8-a -isystem ${OHOS_TOOLCHAIN}/include"
CURPWD=${PWD}
DISABLE="--disable-protoc"
# 编译 protobuf
PROTOBUF_PACKAGE_PATH=${CURPWD}/protobuf-all-3.6.1.tar.gz # 压缩包路径
PROTOBUF_NAME=protobuf-3.6.1 # 解压名称
PROTOBUF_BUILD_PATH=${CURPWD}/build/protobuf # 输出路径
rm -fr ${PROTOBUF_NAME}
if [ ! -d ${PROTOBUF_NAME} ]; then # 如果 protobuf-3.6.1 不存在,则从压缩包中解压
tar -xvf ${PROTOBUF_PACKAGE_PATH} -C ${CURPWD} ; wait
fi
cd ${PROTOBUF_NAME}
make clean 2>/dev/null
./configure --prefix=${PROTOBUF_BUILD_PATH} --host=arm CC="${CC}" CXX="${CXX}" CFLAGS="${CFLAGS}"
make
make install
cd ${CURPWD}
# 编译 protobuf-c
export PKG_CONFIG_PATH=${PROTOBUF_BUILD_PATH}/lib/pkgconfig/ # 依赖项
export CPPFLAGS=-I${PROTOBUF_BUILD_PATH}/include # 依赖头文件路径
export LIBS=-L${PROTOBUF_BUILD_PATH}/lib # 依赖库路径
PROTOBUF_C_PACKAGE_PATH=${CURPWD}/protobuf-c-1.4.1.tar.gz # 压缩包路径
PROTOBUF_C_NAME=protobuf-c-1.4.1 # 解压名称
PROTOBUF_C_BUILD_PATH=${CURPWD}/build/proto-c # 输出路径
rm -fr ${PROTOBUF_C_NAME}
if [ ! -d ${PROTOBUF_C_NAME} ]; then # 如果 protobuf-c-1.4.1 不存在,则从压缩包中解压
tar -xvf ${PROTOBUF_C_PACKAGE_PATH} -C ${CURPWD} ; wait
fi
cd ${PROTOBUF_C_NAME}
make clean 2>/dev/null
./configure --prefix=${PROTOBUF_C_BUILD_PATH} --host=arm ${DISABLE} CC="${CC}" CXX="${CXX}" CFLAGS="${CFLAGS}"
make -v
make install
cd ${CURPWD}
# 编译 protobuf-c
export PKG_CONFIG_PATH=${PROTOBUF_BUILD_PATH}/lib/pkgconfig/ # 依赖项
export CPPFLAGS=-I${PROTOBUF_BUILD_PATH}/include # 依赖头文件路径
export LIBS=-L${PROTOBUF_BUILD_PATH}/lib # 依赖库路径
PROTOBUF_C_PACKAGE_PATH=${CURPWD}/protobuf-c-1.4.1.tar.gz # 压缩包路径
PROTOBUF_C_NAME=protobuf-c-1.4.1 # 解压名称
PROTOBUF_C_BUILD_PATH=${CURPWD}/build/proto-c # 输出路径
rm -fr ${PROTOBUF_C_NAME}
if [ ! -d ${PROTOBUF_C_NAME} ]; then # 如果 protobuf-c-1.4.1 不存在,则从压缩包中解压
tar -xvf ${PROTOBUF_C_PACKAGE_PATH} -C ${CURPWD} ; wait
fi
cd ${PROTOBUF_C_NAME}
make clean 2>/dev/null
./configure --prefix=${PROTOBUF_C_BUILD_PATH} --host=arm ${DISABLE} CC="${CC}" CXX="${CXX}" CFLAGS="${CFLAGS}"
make -v
make install
编译报错如下