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-static-x86_64-msvc_md-win32 13.6.2 windows.zip
).
The Worker SDK in C++ is a native library, so it is compiled for a large variety of platforms, architectures and configurations. Each package contains native libraries built for a particular configuration, plus the required header files. 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, you can obtain the relevant worker package as follows:
Assuming that
worker_dir
is<project_root>/workers/<your_worker>
, add the following configuration within<worker_dir>/spatialos_worker_packages.json
to download the header files and libraries to<worker_dir>/dependencies/worker_sdk
:{ "targets": [ { "path": "worker_sdk", "type": "worker_sdk", "packages": [ { "name": "<package>" } ] } ] }
You can specify multiple packages at once as multiple entries in the
targets
array with different paths if desired. For example, if you’re building a worker using C and C++, you can download both the Multithreaded Dynamic (MD) and Multithreaded Dynamic Debug (MDd) packages, and point the MSVC project to link against the different packages depending on the configuration (Debug / Release). You can also specify packages for macOS and Linux so that you can use them when building on other platforms.In this example, the
spatialos_worker_packages.json
will look similar to:{ "targets": [ { "path": "worker_sdk/windows/debug", "type": "worker_sdk", "packages": [ { "name": "cpp-static-x86_64-msvc_mdd-win32" } ] }, { "path": "worker_sdk/windows/release", "type": "worker_sdk", "packages": [ { "name": "cpp-static-x86_64-msvc_md-win32" } ] } ] }
In a terminal,
cd
to the directory containing yourspatialos_worker_packages.json
and runspatial package unpack
.This will unpack the Worker SDK (
type
) for the specified language and platform into the specified sub-directory (path
). 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.