This directory contains an example of how to use the C API of sea-codec from a C application.
- Rust (cargo)
- CMake
- A C compiler (GCC, Clang, MSVC)
main.c: A simple C program that generates a sine wave, encodes it usingsea-codec, and decodes it back.CMakeLists.txt: A CMake build file demonstrating how to link against thesea-codeclibrary.
-
Build the Rust library:
From the root of the repository:
cargo build --release
This will generate the static and dynamic libraries in
target/release. -
Build the C example:
cd examples/c_api mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build .
-
Run the example:
On Linux/macOS:
./c_example
On Windows:
.\Release\c_example.exe
(Note: If linking dynamically, ensure
sea_codec.dllis in the same directory or in PATH).
The C header file is located at include/sea_codec.h. You should include this in your C/C++ projects.
To build a static library for a different platform (e.g., ARM Cortex-M3), use rustup to add the target and cargo to build:
rustup target add thumbv7m-none-eabi
cargo build --release --target thumbv7m-none-eabi --features c-api