docs/docs/00100-intro/00200-quickstarts/00700-cpp.md
import { InstallCardLink } from "@site/src/components/InstallCardLink"; import { StepByStep, Step, StepText, StepCode } from "@site/src/components/Steps";
Get a SpacetimeDB C++ app running in under 5 minutes.
After installing the SDK, run the appropriate emsdk_env script (PowerShell or Bash) so emcc and the CMake toolchain file are available on PATH.
./emsdk install 4.0.21 ./emsdk activate 4.0.21 source ./emsdk_env.sh
</StepCode>
</Step>
<Step title="Create your project">
<StepText>
Use the CLI-managed workflow with `spacetime build`, which wraps CMake + `emcc` for you, starts the local server, builds/publishes your module, and generates client bindings.
</StepText>
<StepCode>
```bash
spacetime dev --template basic-cpp
</StepCode>
<StepText>
Need manual control? You can still drive CMake+emcc directly (see `spacetimedb/CMakeLists.txt`), but the recommended path is `spacetime build`/`spacetime dev`.
</StepText>
struct Person { std::string name; }; SPACETIMEDB_STRUCT(Person, name) SPACETIMEDB_TABLE(Person, person, Public)
SPACETIMEDB_REDUCER(add, ReducerContext ctx, std::string name) { ctx.db[person].insert(Person{name}); return Ok(); }
SPACETIMEDB_REDUCER(say_hello, ReducerContext ctx) { for (const auto& person : ctx.db[person]) { LOG_INFO("Hello, " + person.name + "!"); } LOG_INFO("Hello, World!"); return Ok(); }
</StepCode>
</Step>
<Step title="Test with the CLI">
<StepText>
Open a new terminal and navigate to your project directory. Then call reducers and inspect data right from the CLI.
</StepText>
<StepCode>
```bash
cd my-spacetime-app
# Insert a person
spacetime call add Alice
# Query the person table
spacetime sql "SELECT * FROM person"
# Call say_hello to greet everyone
spacetime call say_hello
# View the module logs
spacetime logs
</StepCode>
SPACETIMEDB_CPP_SDK_DIR before running spacetime dev/spacetime build.-fno-exceptions).emcc is not found, re-run the appropriate emsdk_env script to populate environment variables.