Skip to content

C

Each release publishes the C library as maplibre-native-c-<preset>.tar.gz, one archive for each preset. A preset names a platform, an architecture, and a backend, such as macos-arm64-metal or linux-gnu-x64-vulkan. OpenGL presets name their context instead of the backend: egl, wgl, or webgl.

Download the archive for your preset and unpack it. The directory inside, maplibre-native-c-<preset>, is the install prefix.

With CMake, point maplibre-native-c_DIR at the prefix’s package config, and link the imported target:

CMakeLists.txt
find_package(maplibre-native-c CONFIG REQUIRED)
target_link_libraries(app PRIVATE maplibre-native-c::maplibre-native-c)
Terminal window
cmake -S . -B build -Dmaplibre-native-c_DIR=<prefix>/lib/cmake/maplibre-native-c
cmake --build build

To link the static library instead, use maplibre-native-c::maplibre-native-c-static.

With another build system, use pkg-config:

Terminal window
export PKG_CONFIG_PATH=<prefix>/share/pkgconfig
cc -std=c23 main.c $(pkg-config --cflags --libs maplibre-native-c) -o main

On Windows, put <prefix>/bin on PATH, or copy the DLLs in it next to the executable. On other platforms, the executable finds the library through the rpath that pkg-config adds.

With xmake 3.1.2 or later, add the distribution repository at a release’s tag:

xmake.lua
add_repositories("maplibre https://github.com/maplibre/maplibre-native-ffi-distribution.git v0.202611.0")
add_requires("maplibre-native-c 0.202611.0", {configs = {backend = "vulkan"}})
target("app")
set_kind("binary")
add_files("main.c")
add_packages("maplibre-native-c")

Leave out backend to use the platform’s default. For musl on Linux, add libc = "musl" to configs.

Register the distribution repository as a Git registry. vcpkg takes a commit hash as the baseline, not a tag, so look up the commit of the release’s tag:

Terminal window
git ls-remote https://github.com/maplibre/maplibre-native-ffi-distribution 'refs/tags/v0.202611.0^{}'
vcpkg-configuration.json
{
"registries": [
{
"kind": "git",
"repository": "https://github.com/maplibre/maplibre-native-ffi-distribution",
"baseline": "<commit>",
"packages": ["maplibre-native-c"]
}
]
}

Choose one backend feature, opengl, metal, or vulkan, and link the CMake target as above:

vcpkg.json
{
"dependencies": [{ "name": "maplibre-native-c", "features": ["vulkan"] }]
}

vcpkg also needs a baseline for its default registry. Keep your manifest’s builtin-baseline, or set "default-registry": null if you take no other vcpkg packages.

With Conan 2, clone the distribution repository and add it as a local recipe index. Pull the clone to see newer releases.

Terminal window
git clone https://github.com/maplibre/maplibre-native-ffi-distribution.git
conan remote add maplibre-native-ffi ./maplibre-native-ffi-distribution --type=local-recipes-index
conan install --requires="maplibre-native-c/0.202611.0" --build=missing \
-o "maplibre-native-c/*:backend=vulkan" -g CMakeDeps -g CMakeToolchain

backend takes metal, opengl, vulkan, webgpu, or default. For musl on Linux, add -o "maplibre-native-c/*:libc=musl".

For Apple platforms, MaplibreNativeC.xcframework.zip holds the library as the framework MaplibreNativeC. Add it to a Swift package as a binary target, with the zip’s checksum from the release’s SHA256SUMS:

Package.swift
.binaryTarget(
name: "MaplibreNativeC",
url: "https://github.com/maplibre/maplibre-native-ffi/releases/download/v0.202611.0/MaplibreNativeC.xcframework.zip",
checksum: "<checksum>"
)

C code includes <MaplibreNativeC/maplibre_native_c.h>.

For Android, native code can link the library from a Kotlin runtime AAR, through Prefab:

build.gradle.kts
android {
buildFeatures {
prefab = true
}
}
dependencies {
implementation("org.maplibre.nativeffi:maplibre-native-ffi-runtime-opengl-android:0.202611.0")
}
CMakeLists.txt
find_package(maplibre-native-c REQUIRED CONFIG)
target_link_libraries(app PRIVATE maplibre-native-c::maplibre-native-c)

Initialize the library once per process, before you create a runtime, with the calling thread’s JNI environment and an Android Context:

android.c
mln_android_init(jni_env, context, NULL);