Description

We want to cross-compile a Golang application (with a libpcap cgo dependency) for a Raspberry Pi running the RDK-B stack. We exported the SDK while building the RDK-B image for the target and attempted to use that to build our Golang app. However, we found that cgo doesn't identify the environment variables exported by the SDK (stdlib.h wasn't found!) and we had to provide the toolchain configuration manually like so: 

CGO_CFLAGS="--sysroot /opt/rdk/2.0/sysroots/cortexa7t2hf-neon-vfpv4-rdk-linux-gnueabi/ -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 -fno-omit-frame-pointer -fno-optimize-sibling-calls" CGO_LDFLAGS="--sysroot /opt/rdk/2.0/sysroots/cortexa7t2hf-neon-vfpv4-rdk-linux-gnueabi/"

Further, even after resolving all the dependencies manually, we found that the target application links to the interpreter /lib/ld-linux.so.3, instead of /lib/ld-linux-armhf.so.3 and the application doesn't run on the Raspberry Pi unless the interpreter is specified. 

However, we found that when we built the application with the Raspberry Pi toolchain (GCC 4.9.3), the compilation was smooth and the application runs fine on the RDK-B Raspberry Pi reference platform. In fact, we only had to use the command,

env CC=arm-linux-gnueabihf-gcc LD=arm-linux-gnueabihf-ld GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 go build

Questions

  1. Are we using the SDK incorrectly or have we built/exported it incorrectly? The problem we're facing seems to be due to a misconfigured SDK.
  2. Is there any difference between the RPI toolchain and the RDK-B SDK one? Can we continue to use the Raspberry Pi toolchain instead of the RDK one? 

  • No labels

3 Comments

  1. Hi,

    Can I know the steps involved in compiling the Glolang application? do you have yocto recipes for the same ?



    1. Hi Rajkumar Narayanan,

      We're using rdkb-2019q2, which doesn't contain built-in support for Go (or recipes in openembedded-core). We're simply building the application using go build (without any Yocto recipes) as shown below:

      env CC=arm-linux-gnueabihf-gcc LD=arm-linux-gnueabihf-ld GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 go build