Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds docs for watcher-c #53

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions watcher-c/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Using the watcher library from C

The watcher can also be used from C by including the `watcher-c.h` file on compilation and in your project.

You can cross compile the library via the `watcher-c/cross-compile.sh` script or download the precompiled library from the releases.

### Compiling the library from source

If you want to compile the library yourself you can follow the following example:

First check out the `next` branch, compile a shared `libwatcher-c.so` library with `gcc` and install
AlliBalliBaba marked this conversation as resolved.
Show resolved Hide resolved
it in the `/usr/local/lib` directory:

```bash
AlliBalliBaba marked this conversation as resolved.
Show resolved Hide resolved
curl -L https://github.com/e-dant/watcher/archive/refs/heads/next.tar.gz | tar xz
cd watcher-next/watcher-c
gcc -o libwatcher-c.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -O3 -Wall -Wextra -fPIC -shared
AlliBalliBaba marked this conversation as resolved.
Show resolved Hide resolved
cp libwatcher-c.so /usr/local/lib/libwatcher-c.so
ldconfig
```

### Using the library in your C code

After installing the library, copy the `watcher-c.h` file to your project and include it in your C code:

```c
#include "watcher-c.h"
```

You will then be able to use the `wtr_watcher_open` and `wtr_watcher_close` functions by linking against the library (`-lwatcher-c`).

`wtr_watcher_close` will always return `false` if the watcher is closed before the first `@live` event has been sent.
AlliBalliBaba marked this conversation as resolved.
Show resolved Hide resolved

Note that the watcher depends on the c++ standard library.
Loading