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
- id: C1 claim: The package loads plugins and resolves symbols. source: S1 evidence: "loading and symbol resolution of Go plugins"
- id: C2 claim: Build a plugin with -buildmode=plugin. source: S1 evidence: "go build -buildmode=plugin"
- id: C3 claim: Open runs package init functions but not main. source: S1 evidence: "The main function is not run"
- id: C4 claim: A plugin is initialized once and cannot be closed. source: S2 evidence: "initialized once, and cannot be closed"
- id: C5 claim: Only Linux, FreeBSD, and macOS are supported. source: S1 evidence: "only on Linux, FreeBSD, and"
Sources
- [S1] plugin package. The Go Authors. https://pkg.go.dev/plugin . License: BSD-3-Clause. Accessed 2026-11-27.
- [S2] plugin.go (source). The Go Authors. https://go.dev/src/plugin/plugin.go . License: BSD-3-Clause. Accessed 2026-11-27.
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
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.},
}
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.
- go-plugin.schema.json (schema; CC-BY-4.0)
- go-plugin.table.json (table; CC-BY-4.0)
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.