Sites

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

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 works with any C compiler that supports the ANSI C standard, or any other language which is designed to work with C libraries. 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 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 will use the multi-threaded dynamic runtime (/MD) in the Release configuration, and the multi-threaded dynamic debug runtime (/MDd) in the Debug configuration.

iOS and Android support is currently in alpha. In particular, iOS apps using SpatialOS do not yet support IPv6 only networks. However, this will be resolved in the near future.

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 c-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

If you’re using the flexible project layout, you don’t need to do this.

Assuming you have a worker set up with a worker configuration file, you can obtain the relevant worker package as follows:

  1. 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": "dependencies/worker_sdk",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "<package_name>"
              }
            ]
          }
        ]
      }
    

    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": "dependencies/worker_sdk/windows/debug",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "c-static-x86_64-msvc_mdd-win32",
                "platform": "windows"
              }
            ]
          },
          {
            "path": "dependencies/worker_sdk/windows/release",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "c-static-x86_64-msvc_md-win32",
                "platform": "windows"
              }
            ]
          },
          {
            "path": "dependencies/worker_sdk/macos",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "c-static-x86_64-clang_libcpp-macos",
                "platform": "macos"
              }
            ]
          },
          {
            "path": "dependencies/worker_sdk/linux",
            "type": "worker_sdk",
            "packages": [
              {
                "name": "c-static-x86_64-gcc_libstdcpp-linux",
                "platform": "linux"
              }
            ]
          }
        ]
      }
    
  2. In a terminal, cd to <worker_dir> and run spatial package unpack (which is done automatically by spatial worker build if unpack dependencies is specified in the build.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 under sdk_version).

Head to Building a worker for the next steps.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums