Skip to content

Library recipes ​

Verified copy-paste recipes for consuming common C/C++ libraries with clap vendor. Every recipe on this page was executed end to end — downloaded, hash-verified, compiled, and run — before being documented. URLs are pinned to exact commits or release tags, and --sha256 makes drift impossible: if upstream changes the bytes, the command fails loudly instead of silently building different code.

clap vendor --list inventories everything vendored so far — archives with their source URL and pinned hash, single files with a live-computed one. Upgrading to a newer pin is --force: the new download is hash-verified before anything existing is touched.

The declarative way — [dependencies] + clap sync ​

Everything below works imperatively, but the reproducible form is declaring the pin once in clap.toml:

toml
[dependencies.json]
url = "https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz"
sha256 = "d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d"
bash
clap sync     # downloads, hash-verifies, extracts into vendor/json
clap run      # #include <nlohmann/json.hpp> just compiles — no -I flag

Or skip writing the table by hand entirely — clap add downloads, pins, and vendors in one command:

bash
clap add https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
# pinned json in clap.toml (sha256 d6c65aca6b1e…) + vendored — ready to build

The include root is added to every build automatically, a missing or drifted dependency fails with the exact remedy, and clap sync re-verified before touching anything existing. Clone the project on a fresh machine and one clap sync reproduces the exact dependency tree — this is the recommended way to consume the recipes below.

nlohmann/json — release archive ​

clap vendor extracts .tar.xz/.zip archives atomically and suggests a working include root:

bash
clap vendor https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz \
  --sha256 d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d
# vendored 53 files into vendor/json — use the printed include root:
clap run main.cpp -I vendor/json/include
cpp
#include <nlohmann/json.hpp>
#include <iostream>
int main() {
    nlohmann::json j = {{"answer", 42}};
    std::cout << "json answer: " << j["answer"] << "\n";
}

Verified output: json answer: 42.

stb_image — or just clap add stb-image — single header ​

bash
clap vendor https://raw.githubusercontent.com/nothings/stb/6b5799bae8a1fe3792691ef4b72ae26434c3e799/stb_image.h \
  --sha256 dfc2aadda6295f67f677587773f25e5bf8c8ad427ed0db7c518525c91e72e020 \
  --output vendor/stb_image.h
c
#define STB_IMAGE_IMPLEMENTATION
#include <stdio.h>
#include <stb_image.h>
int main(void) {
    int w, h, ch;
    unsigned char *px = stbi_load("test.png", &w, &h, &ch, 0);
    if (!px) return 1;
    printf("decoded %dx%d channels=%d\n", w, h, ch);
    stbi_image_free(px);
    return 0;
}
bash
clap run imgtest.c -I vendor

Verified output with a 2×2 PNG: stb_image decoded 2x2 channels=3.

cJSON — a compiled library, zero configuration ​

Compiled (non-header-only) libraries declare their sources in the dependency entry — cJSON.c compiles and links into your project automatically. Verified end-to-end against the real v1.7.18 tarball:

toml
[dependencies.cjson]
url = "https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.18.tar.gz"
sha256 = "3aa806844a03442c00769b83e99970be70fbef03735ff898f4811dd03b9f5ee5"
sources = ["cJSON.c"]
bash
clap sync   # vendored — cJSON.c joins every build of this project
clap run    # prints cjson: {"answer":42}
c
#include <stdio.h>
#include <cJSON.h>
int main(void) {
    cJSON *root = cJSON_CreateObject();
    cJSON_AddNumberToObject(root, "answer", 42);
    char *out = cJSON_PrintUnformatted(root);
    printf("cjson: %s\n", out);
    cJSON_free(out);
    cJSON_Delete(root);
    return 0;
}

The imperative two-file equivalent — vendor cJSON.h and cJSON.c individually and pass the .c on the command line — still works exactly as before.

argparse — or just clap add argparse — modern C++ CLI parsing ​

bash
clap vendor https://raw.githubusercontent.com/p-ranav/argparse/v3.2/include/argparse/argparse.hpp \
  --sha256 1aed230e73c21fd8adda36b84199b4e2f7ba434bdc5492a5d3052bcc1bd5aee7 \
  --output vendor/argparse.hpp
cpp
#include <iostream>
#include <argparse.hpp>
int main(int argc, char *argv[]) {
    argparse::ArgumentParser program("argtest");
    program.add_argument("--count").default_value(3).scan<'i', int>();
    program.parse_args(argc, argv);
    std::cout << "count: " << program.get<int>("--count") << "\n";
}
bash
clap run argtest.cpp -I vendor -- --count 7

Verified output: argparse count: 7 — everything after -- is forwarded to the program.

doctest — zero-setup, nothing to vendor ​

doctest needs no recipe at all: #include <doctest/doctest.h> compiles out of the box because CLAP bootstraps the pinned, hash-verified single header into the user cache on first use. clap init --template doctest scaffolds a working test project.

SQLite — the extreme case, as a declared dependency ​

The full SQLite amalgamation (~260k lines in one translation unit) works as a declarative dependency — verified end-to-end: clap sync vendors it, sqlite3.c compiles into the project, #include <sqlite3.h> resolves with zero flags, and SELECT 40+2 answers 42:

toml
[dependencies.sqlite]
url = "https://sqlite.org/2025/sqlite-amalgamation-3510100.zip"
sha256 = "84a85d6a1b920234349f01720912c12391a4f0cb5cb998087e641dee3ef8ef2e"
sources = ["sqlite3.c"]

For one-off command-line builds of the amalgamation see Real-world builds, including compile times.

When a library is not single-header ​

  • Libraries shipped as release archives (nlohmann/json, SQLite) vendor directly from .zip/.tar.gz/.tar.xz URLs.
  • Libraries with real build systems (curl, openssl) are out of scope for vendoring — use the pkg-config dependency workflow with clap lock/clap deps instead, or drive their own CMake build. CLAP is honest about this boundary rather than pretending to be a package manager.

Evaluated and intentionally not pinned ​

These libraries come up often. Each was actually downloaded, compiled and exercised before deciding — the reason for exclusion is upstream reality, not lack of effort. If upstream fixes the root cause, the pin becomes possible.

  • ubench (sheredom's microbenchmark harness) — the Windows path assumes MSVC (_MSC_VER only, so clang/mingw toolchains cannot compile it), and the Linux clock path includes time.h only under __GLIBC__, so musl targets have no struct timespec. clap's cross-compilation story is exactly mingw + musl, where this library cannot work by design.
  • tinycthread — threads glue that is glibc-shaped; the same musl/mingw coverage problem.
  • miniz 3.x — requires a cmake-generated header (miniz_export.h) that does not exist in the source archive; generated-build-system artifacts are outside the zero-setup model.
  • stb_image_resize / stb_image_resize2, stb_textedit, stb_sprintf — upstream itself marks these deprecated. Pinning deprecated code would be a lie about the registry's quality bar. (stb_textedit additionally cannot demonstrate anything alone — it needs font metrics supplied by a host application.)
  • bestline (jart's line-editing library) — evaluated as a maintained linenoise alternative, but its POSIX surface is unconditional (poll.h, sys/ioctl.h, sys/mman.h with no _WIN32 path at all): it is cosmopolitan-libc-oriented, so under zig targeting native Windows it does not compile. It would pin with the exact same POSIX-only platforms constraint linenoise already carries, adding no coverage — one line editor in that niche is enough.
  • microui (rxi's immediate-mode GUI) — its command arena packs variable-size commands back-to-back with no alignment, so the command stream is misaligned by construction. zig's debug build traps the misaligned access — correctly, because it is genuine UB — which means the library crashes in the default build profile for the most basic possible usage. A pin whose hello-world dies in debug mode is no pin at all.
  • mbedtls as a small pin — it is pinned and works, but note it needs its full source tree (~110 files); the trimmed-down variants floating around missing the entropy sources do not link on Windows, where the entropy backend is BCryptGenRandom (the pin carries windows:bcrypt for exactly this reason).