This post details a process for creating a statically linked Go executable that utilizes CGO dependencies through Zig. Normally, CGO generates dynamically linked executables, but for stability, static linking is preferred. By setting up a Zig library and writing a simple library function that uses the C ABI, along with its corresponding C header file, you can build the library using Zig. The process includes creating a Go program that calls the Zig library and building the executable with specific bash commands to ensure static linking. The result is a working Go executable that is statically linked, demonstrating the power of tools like Go and Zig. Consider supporting the Zig Software Foundation if you find this information helpful.
https://calabro.io/zig-cgo