Skip to content

Compiling CPP code

Sibo Wang edited this page Apr 30, 2025 · 2 revisions

The following aspects of Spotlight's control/data acquisition code are written in C++:

The main reason for implementing the main GUI program in C++ is performance—recording behavior frames at >300 FPS imposes a heavy load on the computer. The other two programs are implemented in C++ because a lot of code from the main recording program can be reused. The C++ source code can be found under the recorder/src folder. The calibrationProcedure and cameraAlignment subfolders contain the appropriate helper programs.

We use CMake for build management. CMake simplifies the compilation process by automatically generating the necessary build files from configuration file called CMakeLists.txt (found at recorder/CMakeLists.txt). This allows us to easily specify which source files to compile, where to find external libraries, and how to link everything together. CMake also keeps the compiled files separate from the source code, maintaining a clean project structure. TODO: Check this

To compile the C++ code, follow the procedure below:

cd spotlight-control/recorder
mkdir build
cd build
cmake ..
make -j8  # "-j8" tells `make` to compile the program using 8 threads in parallel
          # if any compile-time error is encountered, rerun with just 1 thread
          # to get the error messages in proper order
make install

The last step, make install, will create a bin folder under recorder which contains the three compiled binary files, spotlight-controller, collect-caliberation-data, and align-cameras.

You can run these programs using the command line. For example:

username@hostname:spotlight-control/recorder/bin$ ./spotlight-controller --help
Usage: RunCalibration [OPTIONS]
Options:
  -h, --help                 Display this help message
  -p, --profile-dir PATH     Path to profile directory (default: ~/Spotlight/default/)
  -v, --verbose              Enable verbose output (debug level)
  --verbosity LEVEL          Set verbosity level (trace, debug, info, warn, error, critical, off)

Optionally, you can cd into a directory that's included in the $PATH environment variable and create symbolic links to the compiled binary files. This way, you can run the program anywhere by simply calling spotlight-controller, etc., without having to specify the full path or first cd into the bin folder first. For example:

username@hostname:~$ spotlight-controller --help
Usage: RunCalibration [OPTIONS]
Options:
  -h, --help                 Display this help message
  -p, --profile-dir PATH     Path to profile directory (default: ~/Spotlight/default/)
  -v, --verbose              Enable verbose output (debug level)
  --verbosity LEVEL          Set verbosity level (trace, debug, info, warn, error, critical, off)

Clone this wiki locally