简体   繁体   中英

Cross Compile grpc with cmake

I'm trying to cross compile grpc.
Intel x86 host; Target is an arm architecture. It's a display running yocto linux.
My build system is working for other projects. Boost does compile, and other binaries compile an run well.

I export the following variables before I start cmake (as suggested by the display supplier Garz&Fricke or now SECO):

export SDKTARGETSYSROOT=/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/imx6guf-guf-linux-gnueabi
export PATH=/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/../x86_64-gufsdk-linux/bin:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-uclibc:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-musl:$PATH
export CCACHE_PATH=/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/../x86_64-gufsdk-linux/bin:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-uclibc:/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-musl:$CCACHE_PATH
export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig
export CONFIG_SITE=/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/site-config-imx6guf-guf-linux-gnueabi
export OECORE_NATIVE_SYSROOT="/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux"
export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"
export OECORE_ACLOCAL_OPTS="-I /opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/share/aclocal"
export PYTHONHOME=/opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr
unset command_not_found_handle
export CC="arm-guf-linux-gnueabi-gcc  -march=armv7-a -marm  -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-guf-linux-gnueabi-g++  -march=armv7-a -marm  -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CPP="arm-guf-linux-gnueabi-gcc -E  -march=armv7-a -marm  -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export AS="arm-guf-linux-gnueabi-as "
export LD="arm-guf-linux-gnueabi-ld  --sysroot=$SDKTARGETSYSROOT"
export GDB=arm-guf-linux-gnueabi-gdb
export STRIP=arm-guf-linux-gnueabi-strip
export RANLIB=arm-guf-linux-gnueabi-ranlib
export OBJCOPY=arm-guf-linux-gnueabi-objcopy
export OBJDUMP=arm-guf-linux-gnueabi-objdump
export AR=arm-guf-linux-gnueabi-ar
export NM=arm-guf-linux-gnueabi-nm
export M4=m4
export TARGET_PREFIX=arm-guf-linux-gnueabi-
export CONFIGURE_FLAGS="--target=arm-guf-linux-gnueabi --host=arm-guf-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"
export CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"
export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types"
export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
export CPPFLAGS=""
export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"
export OECORE_DISTRO_VERSION="jethro-10.0-r7885-0"
export OECORE_SDK_VERSION="jethro-10.0-r7885-0"
export ARCH=arm
export CROSS_COMPILE=arm-guf-linux-gnueabi-

# Append environment subscripts
if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
            source $envfile
    done
fi
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
            source $envfile
    done
fi

I download grpc from github and start cmake. Cmake detects the cross compiler correctly as can be seen in the cmake output.

git clone https://github.com/grpc/grpc
cd grpc
git submodule update --init
cd cmake
mkdir build
cd build
cmake ../..

cmake output:

-- The C compiler identification is GNU 5.2.0
-- The CXX compiler identification is GNU 5.2.0
-- Check for working C compiler: /opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi/arm-guf-linux-gnueabi-gcc
-- Check for working C compiler: /opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi/arm-guf-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi/arm-guf-linux-gnueabi-g++
-- Check for working CXX compiler: /opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi/arm-guf-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
CMake Warning at third_party/abseil-cpp/CMakeLists.txt:70 (message):
  A future Abseil release will default ABSL_PROPAGATE_CXX_STD to ON for CMake
  3.8 and up.  We recommend enabling this option to ensure your project still
  builds correctly.


-- Looking for res_servicename
-- Looking for res_servicename - not found
-- Looking for res_servicename in resolv
-- Looking for res_servicename in resolv - not found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for socket
-- Looking for socket - found
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for include file sys/types.h
-- Looking for include file sys/types.h - found
-- Looking for include file sys/socket.h
-- Looking for include file sys/socket.h - found
-- Looking for include file arpa/inet.h
-- Looking for include file arpa/inet.h - found
-- Looking for include file arpa/nameser_compat.h
-- Looking for include file arpa/nameser_compat.h - found
-- Looking for include file arpa/nameser.h
-- Looking for include file arpa/nameser.h - found
-- Looking for include file assert.h
-- Looking for include file assert.h - found
-- Looking for include file errno.h
-- Looking for include file errno.h - found
-- Looking for include file fcntl.h
-- Looking for include file fcntl.h - found
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Looking for include file limits.h
-- Looking for include file limits.h - found
-- Looking for include file malloc.h
-- Looking for include file malloc.h - found
-- Looking for include file memory.h
-- Looking for include file memory.h - found
-- Looking for include file netdb.h
-- Looking for include file netdb.h - found
-- Looking for include file netinet/in.h
-- Looking for include file netinet/in.h - found
-- Looking for include file net/if.h
-- Looking for include file net/if.h - found
-- Looking for include file signal.h
-- Looking for include file signal.h - found
-- Looking for include file socket.h
-- Looking for include file socket.h - not found
-- Looking for include file stdbool.h
-- Looking for include file stdbool.h - found
-- Looking for include file stdint.h
-- Looking for include file stdint.h - found
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for include file strings.h
-- Looking for include file strings.h - found
-- Looking for include file string.h
-- Looking for include file string.h - found
-- Looking for include file stropts.h
-- Looking for include file stropts.h - found
-- Looking for include file sys/ioctl.h
-- Looking for include file sys/ioctl.h - found
-- Looking for include file sys/param.h
-- Looking for include file sys/param.h - found
-- Looking for include file sys/select.h
-- Looking for include file sys/select.h - found
-- Looking for include file sys/stat.h
-- Looking for include file sys/stat.h - found
-- Looking for include file sys/time.h
-- Looking for include file sys/time.h - found
-- Looking for include file sys/uio.h
-- Looking for include file sys/uio.h - found
-- Looking for include file time.h
-- Looking for include file time.h - found
-- Looking for include file dlfcn.h
-- Looking for include file dlfcn.h - found
-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for include files sys/types.h, netinet/tcp.h
-- Looking for include files sys/types.h, netinet/tcp.h - found
-- Looking for include files winsock2.h, windows.h
-- Looking for include files winsock2.h, windows.h - not found
-- Looking for 3 include files winsock2.h, ..., windows.h
-- Looking for 3 include files winsock2.h, ..., windows.h - not found
-- Looking for include files winsock.h, windows.h
-- Looking for include files winsock.h, windows.h - not found
-- Looking for include file windows.h
-- Looking for include file windows.h - not found
-- Performing Test HAVE_SOCKLEN_T
-- Performing Test HAVE_SOCKLEN_T - Success
-- Performing Test HAVE_TYPE_SOCKET
-- Performing Test HAVE_TYPE_SOCKET - Failed
-- Performing Test HAVE_BOOL_T
-- Performing Test HAVE_BOOL_T - Success
-- Performing Test HAVE_SSIZE_T
-- Performing Test HAVE_SSIZE_T - Success
-- Performing Test HAVE_LONGLONG
-- Performing Test HAVE_LONGLONG - Success
-- Performing Test HAVE_SIG_ATOMIC_T
-- Performing Test HAVE_SIG_ATOMIC_T - Success
-- Performing Test HAVE_STRUCT_ADDRINFO
-- Performing Test HAVE_STRUCT_ADDRINFO - Success
-- Performing Test HAVE_STRUCT_IN6_ADDR
-- Performing Test HAVE_STRUCT_IN6_ADDR - Success
-- Performing Test HAVE_STRUCT_SOCKADDR_IN6
-- Performing Test HAVE_STRUCT_SOCKADDR_IN6 - Success
-- Performing Test HAVE_STRUCT_SOCKADDR_STORAGE
-- Performing Test HAVE_STRUCT_SOCKADDR_STORAGE - Success
-- Performing Test HAVE_STRUCT_TIMEVAL
-- Performing Test HAVE_STRUCT_TIMEVAL - Success
-- Looking for AF_INET6
-- Looking for AF_INET6 - found
-- Looking for O_NONBLOCK
-- Looking for O_NONBLOCK - found
-- Looking for FIONBIO
-- Looking for FIONBIO - found
-- Looking for SIOCGIFADDR
-- Looking for SIOCGIFADDR - found
-- Looking for MSG_NOSIGNAL
-- Looking for MSG_NOSIGNAL - found
-- Looking for PF_INET6
-- Looking for PF_INET6 - found
-- Looking for SO_NONBLOCK
-- Looking for SO_NONBLOCK - not found
-- Looking for CLOCK_MONOTONIC
-- Looking for CLOCK_MONOTONIC - found
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID - Success
-- Performing Test HAVE_LL
-- Performing Test HAVE_LL - Success
-- Looking for bitncmp
-- Looking for bitncmp - not found
-- Looking for closesocket
-- Looking for closesocket - not found
-- Looking for CloseSocket
-- Looking for CloseSocket - not found
-- Looking for connect
-- Looking for connect - found
-- Looking for fcntl
-- Looking for fcntl - found
-- Looking for freeaddrinfo
-- Looking for freeaddrinfo - found
-- Looking for getaddrinfo
-- Looking for getaddrinfo - found
-- Looking for getenv
-- Looking for getenv - found
-- Looking for gethostbyaddr
-- Looking for gethostbyaddr - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for gethostname
-- Looking for gethostname - found
-- Looking for getnameinfo
-- Looking for getnameinfo - found
-- Looking for getservbyport_r
-- Looking for getservbyport_r - found
-- Looking for getservbyname_r
-- Looking for getservbyname_r - found
-- Looking for gettimeofday
-- Looking for gettimeofday - found
-- Looking for if_indextoname
-- Looking for if_indextoname - found
-- Looking for inet_net_pton
-- Looking for inet_net_pton - not found
-- Looking for inet_ntop
-- Looking for inet_ntop - found
-- Looking for inet_pton
-- Looking for inet_pton - found
-- Looking for ioctl
-- Looking for ioctl - found
-- Looking for ioctlsocket
-- Looking for ioctlsocket - not found
-- Looking for IoctlSocket
-- Looking for IoctlSocket - not found
-- Looking for recv
-- Looking for recv - found
-- Looking for recvfrom
-- Looking for recvfrom - found
-- Looking for send
-- Looking for send - found
-- Looking for setsockopt
-- Looking for setsockopt - found
-- Looking for socket
-- Looking for socket - found
-- Looking for strcasecmp
-- Looking for strcasecmp - found
-- Looking for strcmpi
-- Looking for strcmpi - not found
-- Looking for strdup
-- Looking for strdup - found
-- Looking for stricmp
-- Looking for stricmp - not found
-- Looking for strncasecmp
-- Looking for strncasecmp - found
-- Looking for strncmpi
-- Looking for strncmpi - not found
-- Looking for strnicmp
-- Looking for strnicmp - not found
-- Looking for writev
-- Looking for writev - found
-- Looking for __system_property_get
-- Looking for __system_property_get - not found
--
-- 3.19.4.0
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS - Success
-- The ASM compiler identification is GNU
-- Found assembler: /opt/guf/GUF-Yocto-jethro-10.0-r7885-0-sdk/sysroots/x86_64-gufsdk-linux/usr/bin/arm-guf-linux-gnueabi/arm-guf-linux-gnueabi-gcc
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Renaming
--     /home/mik/ThirdParty/grpc/third_party/zlib/zconf.h
-- to 'zconf.h.included' because this file is included with zlib
-- but CMake generates it automatically in the build directory.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mik/ThirdParty/grpc/cmake/build

After that, I build with make and get an error:

    make
    ...
    [ 20%] Building C object third_party/cares/cares/src/lib/CMakeFiles/c-ares.dir/inet_net_pton.c.o
    [ 20%] Building C object third_party/cares/cares/src/lib/CMakeFiles/c-ares.dir/inet_ntop.c.o
    [ 20%] Building C object third_party/cares/cares/src/lib/CMakeFiles/c-ares.dir/windows_port.c.o
    [ 21%] Linking C static library ../../lib/libcares.a
    [ 21%] Built target c-ares
    Scanning dependencies of target random_internal_platform
    [ 21%] Building CXX object third_party/abseil-cpp/absl/random/CMakeFiles/random_internal_platform.dir/internal/randen_round_keys.cc.o
    [ 21%] Linking CXX static library libabsl_random_internal_platform.a
    [ 21%] Built target random_internal_platform
    Scanning dependencies of target random_internal_randen_hwaes_impl
    [ 21%] Building CXX object third_party/abseil-cpp/absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o
    arm-guf-linux-gnueabi-g++: error: unrecognized command line option '-maes'
    arm-guf-linux-gnueabi-g++: error: unrecognized command line option '-msse4.1'
    make[2]: *** [third_party/abseil-cpp/absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/build.make:63: third_party/abseil-cpp/absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o] Error 1
    make[1]: *** [CMakeFiles/Makefile2:4239: third_party/abseil-cpp/absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/all] Error 2
    make: *** [Makefile:152: all] Error 2

arm-guf-linux-gnueabi-g++: error: unrecognized command line option '-maes'
arm-guf-linux-gnueabi-g++: error: unrecognized command line option '-msse4.1'

The target cpu does not support SSE, so yes the compiler does not know of this option.

So why does cmake set this option for this on module. Is there an other environment variable I have to set?

Thanks again for your help, Michael

You may want to specify CMAKE_SYSTEM_PROCESSOR option for cmake so that it can choose right parameters when building them.

With the hint from Esun Kim I managed to fix the issue using a toolchain file with

SET(CMAKE_SYSTEM_NAME "Linux")
SET(CMAKE_SYSTEM_PROCESSOR "armv7l")

However, now a have an interal compiler error much later in the compilation process.

/grpc/src/core/lib/slice/percent_encoding.cc:60:27: internal compiler error: Segmentation fault
 constexpr CompatibleTable g_compatible_table;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM