Linking Go Programs
Explore the process of linking Go packages into a single executable using the go build command. Understand how Go manages debug information and linking configurations. Learn about embedding additional data into your Go programs to create standalone binaries that simplify deployment and distribution.
We'll cover the following...
To build programs, we need to link these packages. The go build command builds the packages and links them into an executable. In this lesson we will examine this process. We will also take a pick into the idea of embedding extra information into Go programs.
Linking Go programs
The go build command linked our multi-git program, too. Linking means taking all the packages that were built or cached (the pkg.a files) and combining them into a single executable. First, some debug information is created because it’s a debug build.
## # github.com/the-gigi/multi-git
#
mkdir -p $WORK/b001/
cat >$WORK/b001/_gomod_.go << 'EOF' # internal
package main
import _ "unsafe"
//go:linkname __debug_modinfo__ runtime.modinfo
var __debug_modinfo__ = "0w\xaf\f\x92t\b\x02A\xe1\xc1\a\xe6\xd6\x18\xe6path\tgithub.com/the-gigi/multi-git\nmod\tgithub.com/the-gigi/multi-git\t(devel)\t\ndep\tgithub.com/fsnotify/fsnotify\tv1.4.7\th1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=\ndep\tgithub.com/hashicorp/hcl\tv1.0.0\th1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=\ndep\tgithub.com/magiconair/properties\tv1.8.0\th1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=\ndep\tgithub.com/mitchellh/go-homedir ...