Setting up the Worker SDK in C++
Requirements
Prerequisites
Follow the SpatialOS tools installation guide (Windows / macOS / Linux). This is a prerequisite for using the Worker SDK.
Supported compilers and runtimes
The Worker SDK in C++ requires a C++11-compliant compiler. We compile native libraries which target at least the following toolchains and platforms:
- Windows: Microsoft Visual Studio 2015 Update 3 and above.
- macOS: Xcode 10 targeting OS X Yosemite (10.10) and above.
- Linux: gcc 5.4.0 with
GLIBCXX_3.4.21
and above. - iOS: iOS 11.4 and above.
- Android: Android API level 24 and above.
- PS4 and Xbox One: See Game console development.
On Windows, if you choose to use a worker package which has been compiled with the /MD
or /MDd
flags (multithreaded dynamic, and multithreaded dynamic debug), then any system which uses these
libraries (including client systems) will also require
Visual C++ Redistributable for Visual Studio 2015.
Usually, MSVC projects use the multi-threaded dynamic runtime (/MD) in the Release configuration,
and the multi-threaded dynamic debug runtime (/MDd) in the Debug configuration.
Packages
You can obtain packages through worker packages,
our package management framework. You can specify these packages in a spatialos_worker_packages.json
or download
them manually by running spatial package get worker_sdk <package_name> <version> <destination zip>
(for
example: spatial package get worker_sdk cpp_headers 14.0.0 windows.zip
).
The Worker SDK in C++ is a header only library that wraps the Worker SDK for C, and is designed to work on the same set of platforms and configurations. To use the Worker SDK for C++, you’ll need to obtain the header files from the package below, plus the relevant Worker SDK to C library to link against. For more information, see Building a worker.
The tables below list all the packages you can retrieve, relevant to the Worker SDK for C++:
Setting up a worker using the SpatialOS build system
Assuming you have a worker set up with a worker configuration file, and
assuming that worker_dir
is <project_root>/workers/<your_worker>
you can obtain the relevant worker package as follows:
First you’ll need to add a file called
<worker_dir>/spatialos_worker_packages.json
to download the header files and libraries to<worker_dir>/dependencies/worker_sdk
.In this file, we specify a set of packages to download during
spatial worker build
. We’ve provided an example below to start you off. In this example, we download both the Multithreaded Dynamic (MD
) and Multithreaded Dynamic Debug (MDd
) packages on Windows, plus binaries for macOS and Linux platforms to enable cross platform development. You’d need to later set up a build system and import the relevant libraries into your chosen build system.spatialos_worker_packages.json
:{ "targets": [ { "path": "dependencies/worker_sdk/headers", "type": "worker_sdk", "packages": [ { "name": "cpp_headers" } ] }, { "path": "dependencies/worker_sdk/lib/windows/debug", "type": "worker_sdk", "packages": [ { "name": "c-static-x86_64-vc140_mdd-win32" } ] }, { "path": "dependencies/worker_sdk/lib/windows/release", "type": "worker_sdk", "packages": [ { "name": "c-static-x86_64-vc140_md-win32" } ] }, { "path": "dependencies/worker_sdk/lib/macos", "type": "worker_sdk", "packages": [ { "name": "c-static-x86_64-clang-macos" } ] }, { "path": "dependencies/worker_sdk/lib/linux", "type": "worker_sdk", "packages": [ { "name": "c-static-x86_64-gcc510-linux" } ] } ] }
In a terminal,
cd
to<worker_dir>
and runspatial package unpack
(which is done automatically byspatial worker build
if unpack dependencies is specified in thebuild.json
).This will unpack the worker package specified above into the sub-directory. The downloaded worker package will be compatible with the SpatialOS SDK version used for your application (specified in
<root>/spatialos.json
undersdk_version
).
Head to Building a worker for the next steps.