This directory contains a C example that demonstrates how to use the LeanStore library via its C API.
- LeanStore built with
release_coropreset (recommended) ordebug_coro(development) - Same vcpkg toolchain used to build LeanStore
cd $LEANSTORE_HOME
cmake --preset release_coro
cmake --build build/release_coro -j $(nproc)
cmake --install build/release_coro --prefix ./dist/release_coroThe library will be installed to $LEANSTORE_HOME/dist/release_coro.
cd $LEANSTORE_HOME/examples/c
# Clean previous build
rm -rf build
# Configure with CMAKE_PREFIX_PATH pointing to LeanStore installation and vcpkg
CMAKE_PREFIX_PATH="../../dist/release_coro:../../build/release_coro/vcpkg_installed/x64-linux" \
cmake -B build -S .
# Build the example
cmake --build build
# Run the example
./build/kv_basic_exampleIf LeanStore is installed to a different location (e.g., system directory or custom prefix):
cd $LEANSTORE_HOME/examples/c
rm -rf build
# Set CMAKE_PREFIX_PATH to include both LeanStore and vcpkg installation directories
cmake -B build -S . \
-DCMAKE_PREFIX_PATH="/path/to/leanstore/install;/path/to/vcpkg/installed/x64-linux"
cmake --build build- The
CMakeLists.txtdeclares a pure C project (project(leanstore-examples C)) and enables C++ language support only for linking (enable_language(CXX)). - It uses
find_package(leanstore CONFIG REQUIRED)to locate the installed LeanStore package. - The C example links to
leanstore::leanstoreand the C++ standard library (stdc++). - All transitive dependencies (Boost, spdlog, rapidjson, etc.) are resolved automatically through LeanStore's CMake package configuration.
- For development builds, you can use the
debug_coropreset, but note that it adds--coverageflags that may affect downstream linking. - The C example uses the C API defined in
include/leanstore/c/leanstore.h. - Ensure your compiler supports C11 (for the example) and C++23 (for the LeanStore library).