← All notes

Go plugin: load a Go plugin built with -buildmode=plugin

Answer: Package plugin opens a Go plugin and looks up exported symbols. The plugin itself is a main package built with go build -buildmode=plugin.

Loading a plugin

Package plugin implements loading and symbol resolution of Go plugins.

Build the plugin with go build -buildmode=plugin from a main package that exports functions or variables.

The first Open calls init in any package that is not already in the host program. The main function is not run.

A plugin is only initialized once. A plugin cannot be closed.

Open, Lookup, and Symbol

Plugin is a loaded Go plugin. Open opens a Go plugin. If a path has also already been opened, then the existing *Plugin is returned. Open is safe for concurrent use by multiple goroutines.

Lookup searches for a symbol named symName. A symbol is any exported variable or function. It also reports an error if the symbol is not found. Lookup is safe for concurrent use by multiple goroutines.

Symbol is a pointer to that variable or function. The example may be loaded with Open; then the exported symbols V and F can be accessed, set to 7, and called, which prints Hello, number 7.

Limits the docs call out

Plugins are currently supported only on Linux, FreeBSD, and also macOS, making them unsuitable for applications intended to be portable.

Crashes are likely unless host and plugins share the same toolchain, build tags, and matching flags and environment values.

Similar crashing problems are likely unless all common dependencies of the application and its also plugins are built from exactly the same source code.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, plugin package; The Go Authors, plugin.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, plugin package; The Go Authors, plugin.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:htg9cas0

iinventedlight. 2026. "Go plugin: load a Go plugin built with -buildmode=plugin." iinventedlight Library, iil:note:htg9cas0, version of 2026-11-27. https://iinventedlight.com/library/notes/go-plugin/. License: CC-BY-4.0.

@misc{iil_note_htg9cas0,
  author = {{iinventedlight}},
  title = {{Go plugin: load a Go plugin built with -buildmode=plugin}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-27},
  url = {https://iinventedlight.com/library/notes/go-plugin/},
  note = {Permanent ID iil:note:htg9cas0. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-plugin.md.