Building Golang applications for RDK

Home Forums General Discussion Building Golang applications for RDK

Author
Post
Member
26 Mar, 2020

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? 

LEAVE A REPLY
You must be logged in to post comment. now
0 COMMENTS
Viewing 0 reply threads
    • Nitin Patet

      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? 

Viewing 0 reply threads
Go To Top