Bitbake / Yocto recipes for cross compiling golang program

For compiling simple golang helloworld program as part of yocto build framework, we need to download meta-golang from and use this meta layer along with poky to build our written bitbake recipes for cross compilation of golang program.

PLEASE NOTE: Starting with OE-Core ‘rocko’ (Yocto Project 2.4), Go support is available directly in OE-Core, and meta-golang is no longer under active development.

For Yocto 2.4 and Later

$ git clone git://
$ cd openembedded-core/
$ git checkout -b thud origin/thud

For Yocto 2.3 and Earlier

$ git clone
$ cd meta-golang

Now, we need to create files with following directory structure as,

$ tree recipes-devtools/examples/
├── files
│ └── helloworld.go

1 directory, 3 files

Now, lets create those files as below,

$ vim recipes-devtools/examples/files/helloworld.go
package main

import "fmt"

func main() {
        fmt.Println("Hello, world !")
$ vim recipes-devtools/examples/
DESCRIPTION = "This is a simple example recipe that cross-compiles a Go program."
SECTION = "examples"

DEPENDS = "golang-cross-arm"

export GOARCH="arm"

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

S = "${WORKDIR}"
$ vim recipes-devtools/examples/

SRC_URI += " \
  file://helloworld.go \

do_compile() {
  go build helloworld.go

do_install() {
  install -d "${D}/${bindir}"
  install -m 0755 "${S}/helloworld" "${D}/${bindir}"

Now, once you integrate this meta-golang with poky, you will be able to compile this simple go language program using bitbake as,

$ bitbake go-helloworld

You may also like to read lot of information about Go Language here. and Yocto Information here


Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )


4 thoughts on “Bitbake / Yocto recipes for cross compiling golang program”

  1. Thanks, this information was very helpful for a project I am working on. I just had one minor problem. In my own recipe I had to use “go-cross-arm” instead of “golang-cross-arm” in the DEPENDS assignment (I’m using Yocto version Rocko).

  2. I am currently doing a project using Yocto 2.7 (Warrior) and I’ve found that the “DEPENDS” statement has changed yet again. Now the dependency is simply “go”.

    • I was too hasty in my previous reply. In the end I had to make a few changes when working with Yocto version 2.7:

      I removed the DEPENDS statement (no go-cross-arm or go).
      I added “inherit go” to include the Go class.
      I modified the do_compile to use a variable from the file go.bbclass to specify the Go compiler executable.
      I had to add a path to the working directory in the compile statement because the Go compiler was accessing ${S}/build and not ${S}.

      For example:

      do_compile() {
      ${GO} build -o ${S}/helloworld ${S}/helloworld.go

      I hope this helps anybody stuck trying to get a similar recipe to work.


Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded