These are the docs for 13.3, an old version of SpatialOS. The docs for this version are frozen: we do not correct, update or republish them. 14.5 is the newest →

Compiling a C++ worker

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

Supported compilers and runtimes

See Requirements.

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.

  • 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.

The correct order of libraries for linking is as follows: WorkerSdk, CoreSdk, protobuf, RakNetLibStatic, grpc++, grpc, gpr, ssl, z.

On some platforms, you need to include compiler and linker options for using threads (e.g. pthreads) and for dynamic loading. An example of flags to include for GCC or Clang is:

-lWorkerSdk -lCoreSdk -lprotobuf -lRakNetLibStatic -lgrpc++ -lgrpc -lgpr -lssl -lz -pthread -ldl

Building for a cloud deployment

After building a project, a certain directory structure is expected when uploading an assembly. We don’t provide generated build scripts, for C++ workers, so 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.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums