Get SpatialOS


You are viewing the docs for 11.0, an old version of SpatialOS. 12.0 is the newest →

Compiling a C++ worker

User code within a C++ worker will normally make use of the worker API defined in <improbable/worker.h> and the C++ generated code, which is based on the user-specified schema.

Supported compilers and runtimes

  • The C++ worker SDK requires a C++11-compliant compiler.

    • Windows: Visual Studio 2015 or later.
    • macOS and Linux: Tested with Xcode 8 on macOS, and GCC 5.4.0 on Linux. Make sure to use the -std=c++11 flag.
  • The C++ worker SDK dynamically links to the C and C++ runtimes.

    • For Visual Studio, the SDK is configured to link against all the multi-threaded runtimes (dynamic, dynamic-debug, static and static-debug). Please make sure to select the correct package for your project when obtaining the SDK. Usually, MSVC projects will use the multi-threaded dynamic runtime (/MD) in the Release configuration, and the multi-threaded dynamic debug runtime (/MDd) in the Debug configuration.

Compiling and linking

In order to build a C++ worker, you need to include header files from, and link against, the following:

  • The C++ worker SDK. This is distributed as a package containing header files in <package dir>/include, and a number of static libraries in <package dir>/lib. You’ll need to link against all the static libraries in the lib folder, in addition to WorkerSdk.lib (on Windows) or libWorkerSdk.a (on macOS and Linux).

  • Generated code. These are the .cc files generated by the SpatialOS schema compiler (spatial schema) from your .schema files, and their corresponding header files.

  • Your code.

Building for a cloud deployment

After building a project, a certain directory structure is expected when uploading an assembly. Usually, we provide generated build scripts, which handle this for you. However, we currently don’t do this for C++ workers. Therefore, the steps of the Build task for your worker (within spatialos.<worker_type>.worker.json) should:

  • Create a zip file containing the worker binary with a name matching the value for the artifact_name specified in the managed worker configuration, under managed then linux.

  • Place the zip file in build/assembly/worker/, so it is picked up when uploading an assembly during spatial cloud upload <assembly name>.

SpatialOS runs managed workers as part of a cloud deployment in a Linux environment running Ubuntu 16.04.2 LTS. Therefore, you need to build a binary that can be executed in this environment. If you are developing on Windows or macOS, we suggest installing Ubuntu 16.04.2 LTS inside a virtual machine using VirtualBox, and making use of the experimental Linux support. This is not required for local deployments during development: just for cloud deployments.

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums