These are examples for ObjectBox C and C++.
Each example is self-contained in its own subdirectory and can be built using CMake.
For convenience, a build.sh script is provided in each example directory,
which puts all build files into a separate directory ("build/").
See the build and run section below for details.
There are four examples console applications that implement a simple task list. Tasks can be added, viewed, and marked as finished to demonstrate typical ObjectBox database operations.
The examples for C++ are:
tasks: C++ applicationtasks-sync: C++ application with sync enabled (requires a ObjectBox Sync server)
The examples for C are:
c-tasks: C applicationc-tasks-lowlevel: C application, but with lesser used lower-level APIs; not the best to start with
There's a C++ example for vector search in the vectorsearch-cities directory.
Prerequisites are CMake 3.14+ and a C/C++ compiler. All examples follow the same setup, and thus we document it only once here.
This is the simplest way on Linux and macOS from the command line.
- Typically, you
cdinto an example directory and run./build.sh(each example has its ownbuild.sh). - Once the build is done, you can run the example: the executable is in the
build/directory and its path is printed to the console during the build. - Run
./build.sh runto build and run the example in one step. - The
./build.shalso accepts--cleanas the first argument to clear the build directory before building.
If you work with a IDE, you can typically just open each example as a CMake project. The IDE will setup everything for you.
If you prefer to use CMake directly (e.g. on a Windows terminal), you can do so as follows:
cmake -S . -B build
cmake --build build
And then run the built executable:
build/objectbox-examples-... # replace ... with the example name
If you want, you can copy an example as a starting point for your own project. Pick the directory of the example that fits best for your needs.
Links and documentation: