# Getting Started with C++

The `Synergy` C++ library drives the SLM backplane with no interpreter and no
dependencies beyond the C++ standard library. Where timing matters, it is the
appropriate choice.

## Where the library is

The C++ library, its examples and a preconfigured build directory are supplied
on the desktop of the `slm-rp4` user:

```text
~/Desktop/synergy_cpp/
├── main.cpp              your program
├── CMakeLists.txt        build definition
├── build/                run make here; the executable appears here
├── examples/             worked examples for each module type
└── lib/
    ├── synergy/          the backplane library
    └── rpi_ws281x/       drives the RGB indicator
```

You edit `main.cpp`, build in `build/`, and run the resulting executable. See
{doc}`building`.

## Prerequisites

The toolchain and CMake are preinstalled. The library communicates with
`/dev/spidev6.0` and `/dev/gpiochip0` through the standard Linux kernel
interfaces, so there are no third-party packages to install and nothing
additional to link. The exception is the RGB LED, which needs `libws2811.a`;
see {doc}`building`.

Confirm the interfaces are present:

```bash
ls -l /dev/spidev6.0 /dev/gpiochip0
```

If `/dev/spidev6.0` is missing, the backplane interface has been lost. See
{doc}`../../troubleshooting`.

## Build on the device

Build on the SLM-RP4 itself. It compiles this project comfortably, and the
supplied build directory is already configured. Cross-compiling from a
workstation is possible but offers little benefit.

If you prefer to work from your own machine, use Visual Studio Code with the
**Remote - SSH** extension, which edits and builds on the device while
presenting the project locally. See {doc}`../accessing-the-device`.

## Before you run anything

```{admonition} Stop the PLC first
:class: danger

The OpenPLC Runtime holds the backplane while the PLC is running. Press **Stop**
in OpenPLC Editor before running your program. See
{doc}`../shared-hardware-rules`.
```

## Permissions

The program needs read and write access to `/dev/spidev6.0` and
`/dev/gpiochip0`. The `slm-rp4` user belongs to the `spi` and `gpio` groups, so
backplane access requires no `sudo`.

Driving the RGB indicator is the exception and requires root. Because the
supplied `main.cpp` includes the indicator library, the example program is run
with `sudo`. See {doc}`../onboard-peripherals`.

## Next

{doc}`building`, covering how to compile and run a program.
