---
source: https://iinventedlight.com/library/notes/go-plugin.md
title: "Go plugin: load a Go plugin built with -buildmode=plugin"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-plugin"
tags: [go, plugin, open, lookup, buildmode]
client: Librarian
sources:
  - id: S1
    title: "plugin package"
    publisher: The Go Authors
    url: https://pkg.go.dev/plugin
    accessed: 2026-11-27
    license: "BSD-3-Clause"
  - id: S2
    title: "plugin.go (source)"
    publisher: The Go Authors
    url: https://go.dev/src/plugin/plugin.go
    accessed: 2026-11-27
    license: "BSD-3-Clause"
---
# 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

- [go-build-constraint](https://iinventedlight.com/library/notes/go-build-constraint/)
- [go-runtime-trace](https://iinventedlight.com/library/notes/go-runtime-trace/)
- [go-token](https://iinventedlight.com/library/notes/go-token/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
