Go
Install
Section titled “Install”Add the module, and the C library’s module for your preset. A preset names a
platform, an architecture, and a
backend, such as
linux-gnu-x64-vulkan or macos-arm64-metal. It needs Go 1.26 or later, with
cgo.
go get maplibre.org/maplibre-native-ffi/bindings/go/maplibre@v0.202611.0 \ maplibre.org/maplibre-native-ffi/go-native/linux-gnu-x64-vulkan@v0.202611.0Import the preset’s module for its side effect. It links the C library statically:
import ( "maplibre.org/maplibre-native-ffi/bindings/go/maplibre" _ "maplibre.org/maplibre-native-ffi/go-native/linux-gnu-x64-vulkan")A preset’s module links only when you build for its GOOS and GOARCH, so a
program can import one preset for each of those that it builds for. Presets that
share them, such as an iOS device and the iOS simulator, or glibc and musl on
Linux, need their imports in separate files with build tags of your own. A link
error that names mln_go_preset_version means that the preset’s module is
missing or imported twice.
Keep both modules at the same version. With a preset’s module from another release, the program panics at startup with an error that names both versions, or fails to link if the releases’ C functions differ.
Every preset has a module except the Windows and web presets. On Windows, use your own build.
Android
Section titled “Android”Initialize the library once per process, before you create a runtime, with the
calling thread’s JNI environment and an Android Context:
err := maplibre.InitAndroid(jniEnv, context)Use your own build
Section titled “Use your own build”To link a C library that you built or downloaded, build with the mln_pkgconfig
tag and leave out the preset’s module. cgo then finds the library through
pkg-config. Download and unpack the C library
for your preset, or build it, and point pkg-config at it:
export PKG_CONFIG_PATH=<prefix>/share/pkgconfiggo build -tags mln_pkgconfigA vendored build needs this too, because go mod vendor leaves out the C
headers that the module carries.
On Windows, cgo links the C library with MSYS2’s Clang: MINGW64 on x64, or
CLANGARM64 on ARM64. Set CC to that environment’s bin/clang.exe and
PKG_CONFIG to its bin/pkgconf.exe. Put the C library’s bin directory and
the environment’s bin directory on PATH.