Skip to content

Instantly share code, notes, and snippets.

@ianfoo
Last active November 12, 2023 23:23
Show Gist options
  • Select an option

  • Save ianfoo/229aa8ea3f36cce794759b46afd1d7f2 to your computer and use it in GitHub Desktop.

Select an option

Save ianfoo/229aa8ea3f36cce794759b46afd1d7f2 to your computer and use it in GitHub Desktop.
Cross compiling and dynamic linking in Go

I'm rough on the details but I think I can shed some light. When compiling for Linux, cgo is optional but desirable. So when you're building on Linux and have libc available, cgo will be enabled and the resulting binary will be dynamically linked to libc. When compiling for Darwin, linking to libSystem is mandatory -- there is no stable syscall interface, and so Go programs always have to link against libsystem or whatever it is. The runtime contains a copy of enough of the libsystem API that it can make system calls via libsystem without having a copy of the headers, and I guess the linker knows how to link against it without actually having the library handy.

https://github.com/golang/go/blob/master/src/runtime/defs_darwin_amd64.go https://github.com/golang/go/blob/master/src/runtime/sys_darwin.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment