Build & features
Two files: the header medius.h and the library libmedius_capi. C++ uses the same header with -std=c++17. First program: Quickstart.
Feature flags Mock, off by default
Mock is a cargo feature on medius-capi and a matching #ifdef in the header.
| Cargo feature | Header macro | Declares | Effect |
|---|---|---|---|
mock | MEDIUS_FEATURE_MOCK | MediusMockBox, the medius_mock_* calls, medius_device_with_mock / _open_mock | A scriptable fake box for tests. See Mock box. |
# build the library with mock
cargo build -p medius-capi --release --features mock
# define the matching macro when compiling
cc app.c -DMEDIUS_FEATURE_MOCK \
-I medius-capi/include -L target/release -lmedius_capi -lpthread -o appThe prebuilt tarball is built without mock. The macro without the feature is a link error; the feature without the macro leaves the declarations hidden.
Linking & loading Header, library, and their flags
Get the two files from a release tarball, or build the crate with the Rust toolchain (cargo build -p medius-capi --release writes the library to target/release/; the header is medius-capi/include/medius.h).
compile ──▶ needs your code + medius.h link ──▶ adds libmedius_capi run ──▶ loads libmedius_capi
| Flag | Points at | Example |
|---|---|---|
-I<dir> | the directory holding medius.h | -I medius-capi/include |
-L<dir> | the directory holding the library | -L target/release |
-lmedius_capi | the library (the linker adds the lib prefix and extension) | resolves libmedius_capi.so |
-lpthread | Linux only; the core spawns reader/keepalive threads | append after -lmedius_capi |
| OS | Shared library | Static library | Note |
|---|---|---|---|
| Linux | libmedius_capi.so | libmedius_capi.a | add -lpthread |
| macOS | libmedius_capi.dylib | libmedius_capi.a | none |
| Windows | medius_capi.dll | medius_capi.lib | link medius_capi.dll.lib (import) or .lib (static); no lib prefix |
// hello.c: proves the library links and loads
#include <medius.h>
#include <stdio.h>
int main(void) {
printf("medius %s, abi %u\n", medius_version_string(), medius_abi_version());
return 0;
}cc hello.c -I medius-capi/include -L target/release -lmedius_capi -lpthread -o hello
LD_LIBRARY_PATH=target/release ./hello
# medius 3.4.6, abi 10-L is link-time only. At run time the loader finds the shared library through LD_LIBRARY_PATH or an rpath on Linux, DYLD_LIBRARY_PATH or @rpath on macOS, and the .dll next to the exe or on PATH on Windows.
Or link the static library (.a / .lib) into the binary.
PackagingPrebuilt tarballs, no vcpkg or Conan port
Each GitHub Release attaches one tarball per platform, medius-capi-<target-triple>.tar.gz. Unpack it and use the flags above.
| Inside the tarball | Contents |
|---|---|
include/medius.h | the header (mock declarations gated by the macro) |
lib/ | the prebuilt libmedius_capi, shared and static, with mock off |
No vcpkg or Conan port: both build from source, and neither supplies a Rust toolchain. Python uses the prebuilt wheel.