A Go library for calling C functions and loading shared libraries without Cgo, enabling cross-compilation and smaller binaries.
Purego is a Go library that provides a foreign function interface (FFI) to call C functions and load shared libraries without requiring Cgo. It enables Go developers to interact with C libraries and system APIs while maintaining the benefits of pure Go compilation, such as cross-compilation support and reduced binary size.
Go developers who need to call C libraries or system APIs but want to avoid the complexities and limitations of Cgo, particularly those working on cross-platform projects or requiring dynamic linking capabilities.
Developers choose Purego over Cgo because it eliminates C dependencies, enabling simpler cross-compilation, faster builds, smaller binaries, and dynamic runtime loading of shared objects, all while offering a fallback to Cgo for incremental porting and unsupported architectures.
A library for calling C functions from Go without Cgo
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Enables direct C function calls without Cgo dependencies, allowing pure Go compilation and eliminating cross-compilation hurdles, as emphasized in the motivation from Ebitengine.
Supports tier 1 platforms like Linux, macOS, and Windows for easy cross-compilation without a C compiler, reducing build environment complexity.
Allows loading symbols from shared objects (.so, .dylib, .dll) at runtime, enabling plugin-like functionality and flexible foreign library integration.
Reduces binary size and speeds up compilation by avoiding Cgo-generated wrapper functions, leading to smaller and faster builds as highlighted in the benefits.
Explicitly labeled as beta software with potential bugs and API breaking changes, making it risky for production use without careful version pinning.
Some architectures (e.g., FreeBSD, NetBSD) require special compiler flags or CGO_ENABLED=1, adding build process overhead and limiting pure Go benefits.
The provided example only handles macOS and Linux; other platforms need additional code, increasing initial setup effort for developers.