时间紧,先大概说明一下,有时间了再补充详细的说明

grpc 交叉编译 需要先编译出pc版的protobuff 和 grpc,安装到指定的路径,在做交叉编译时需要protoc 和grpc_cpp_plugin工具。这两个工具也也是在编译时会生成,交叉编译过程中要屏蔽掉使用交叉编译后的工具。

先上配置

#! /bin/sh

export HOST=arm-hisiv400-linux
export CROSS=arm-hisiv400-linux-
export CC=${CROSS}gcc
export AR=${CROSS}ar
export CPP=${CROSS}cpp
export CXX=${CROSS}g++
export STRIP=${CROSS}strip
export RANLIB=${CROSS}ranlib

export CFLAGS=-I$PWD/build/include
export LDFLAGS=-L$PWD/build/lib
export PREFIX=$PWD/build
export SYS_INCLUDE_ROOT=/opt/hisi-linux/x86-arm/arm-hisi400-linux/target

cd grpc-1.14.1
./build.sh && make clean && make && make install
cd -

 

 

CMakeLists.txt.pre 我将原始的CMakeLists.txt备份成了CMakeLists.txt.pre

sed指令为了使用x86 平台上的工具

cp ./CMakeLists.txt.pre ./CMakeLists.txt;\
rm CMakeCache.txt;    \
sed -i 's/$<TARGET_FILE:grpc_cpp_plugin>/\.\.\/build\/x86\/bin\/grpc_cpp_plugin/g' CMakeLists.txt;
cmake  -G "Unix Makefiles"     -DCMAKE_INSTALL_PREFIX=${PREFIX} \
                        -DCMAKE_INSTALL_LIBDIR=${PREFIX}/lib \
                        -DCMAKE_FIND_ROOT_PATH=${PREFIX} \
                        -DTARGET_LINK_LIBRARIES:STRING=${PREFIX}/lib  \
                        -DLINK_LIBRARIES:STRING=${PREFIX}/lib \
                        -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} \
                        -DgRPC_ZLIB_PROVIDER:STRING=package \
                        -DgRPC_CARES_PROVIDER:STRING=package \
                        -Dc-ares_DIR:PATH=${PREFIX}/lib/cmake/c-ares    \
                        -DgRPC_PROTOBUF_PROVIDER:STRING=package \
                        -DgRPC_PROTOBUF_PACKAGE_TYPE:STRINGS=MODULE \
                        -DOPENSSL_LIBRARIES=${PREFIX}/lib \
                        -DOPENSSL_INCLUDE_DIR=${PREFIX}/include \
                        -DgRPC_SSL_PROVIDER:STRING=package \
                        -DgRPC_GFLAGS_PROVIDER:STRING=package \
                        -DPROTOBUF_PROTOC_EXECUTABLE:FILEPATH=/usr/local/bin/protoc \
                        -DgRPC_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS:BOOL=ON

 

编译到48%报错如下

[ 48%] Built target grpc_unsecure
[ 48%] Linking C executable check_epollexclusive
/opt/hisi-linux/x86-arm/arm-hisiv400-linux/bin/../lib/gcc/arm-hisiv400-linux-gnueabi/4.8.3/../../../../arm-hisiv400-linux-gnueabi/bin/ld: warning: libstdc++.so.6, needed by libgrpc.so, not found (try using -rpath or -rpath-link)
libgrpc.so:对‘__aeabi_atexit@CXXABI_ARM_1.3.3’未定义的引用
libgrpc.so:对‘vtable for __cxxabiv1::__class_type_info@CXXABI_1.3’未定义的引用
libgrpc.so:对‘__gxx_personality_v0@CXXABI_1.3’未定义的引用
libgrpc.so:对‘__cxa_end_cleanup@CXXABI_1.3’未定义的引用
libgrpc.so:对‘vtable for __cxxabiv1::__si_class_type_info@CXXABI_1.3’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/check_epollexclusive.dir/build.make:101: recipe for target 'check_epollexclusive' failed
make[2]: *** [check_epollexclusive] Error 1
CMakeFiles/Makefile2:419: recipe for target 'CMakeFiles/check_epollexclusive.dir/all' failed
make[1]: *** [CMakeFiles/check_epollexclusive.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2

CMakeLists.txt中 如下部分屏蔽掉

#add_executable(check_epollexclusive
#  test/build/check_epollexclusive.c
#)
#
#
#target_include_directories(check_epollexclusive
#  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
#  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
#  PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
#  PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
#  PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
#  PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
#  PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
#  PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
#  PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
#  PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
#)
#
#target_link_libraries(check_epollexclusive
#  ${_gRPC_ALLTARGETS_LIBRARIES}
#  grpc
#  gpr
#)
#

 

 

 

Logo

更多推荐