Create a .wasm File Written in C++

To create .wasm files written in C++ you must have the EDJX C++ SDK and the corresponding WASI SDK installed on your environment.

To install the required SDKs:

  1. Make the /opt/edjx-cpp-sdk directory.

  2. Download the EDJX C++ SDK using one of the following methods:

    • Clone the latest EDJX C++ SDK.

      git clone --depth 1 /opt/edjx-cpp-sdk


    • Make a /opt/edjx-cpp-sdk-$<EDJX_SDK_VERSION>-wasi-sdk-$<WASI_SDK_VERSION> directory.

      Where, $<EDJX_SDK_VERSION> is the EDJX version and $<WASI_SDK_VERSION> is the WASI version matching the EDJX release.
      For example, v21.11.1-wasi-12 and wasi-sdk-12.0, respectively.

      Download and upzip the EDJX C++ SDK from the edjx-cpp-sdk build GitHub page.

      tar -xvf edjx-cpp-sdk-${EDJX_SDK_VERSION}-wasi-${WASI_SDK_VERSION}.tar.gz -C /opt
      ln -s /opt/edjx-cpp-sdk-${EDJX_SDK_VERSION}-wasi-${WASI_SDK_VERSION} /opt/edjx-cpp-sdk
  3. Make the /opt/wasi-sdk directory.

  4. Install the WASI SDK to /opt/wasi-sdk (so that the path to the bundled compiler is /opt/wasi-sdk/bin/clang++).


    At this point you should have two directories under the /opt directory,
    edjx-cpp-sdk or edjx-cpp-sdk-v21.11.1-wasi-12-wasi-sdk-12.0 and wasi-sdk.

  5. Download the WASI C++ SDK from the WebAssembly/wasi-sdk/releases GitHub repository.
    For example,


    This repository provides the necessary C and C++ standard library functions required to build C++ serverless functions.

  6. Unzip the matching release number (wasi-sdk-12.0) file to the /opt/wasi-sdk directory.
    Make sure the WASI SDK has the same version identifier as the EDJX SDK.
    For example, wasi-sdk-12.0 and edjx-cpp-sdk-version#-wasi-12.0.


    At this point you should have two directories and one tar file under the /opt directory. Delete the tar file, as desired.


    Make sure that the bundled compiler is in the /opt/wasi-sdk/bin/clang++ directory.

  7. Clone the EDJX C++ Example code repo GitHub repository to your environment.
    This repository contains samples to help you build C++ serverless functions. The functions can then be built and deployed to the EDJX peer-to-peer network using the EDJX Console, CLI, or VS Code Extension.

    See the files in the EDJX GitHub repository from advanced installation options.

To create, build, and deploy EDJX functions written in C++:

  1. Create the function:

  2. Build the function:

    • Console - Create Function

    • CLI - function build command

    • VS Code - Build a Function
      See also Add a Function and Deploy a Function.
      By default, the files are created with the following file structure and the resulting WASM file is saved in <application>/bin/<app>.wasm, as shown below.

      Project Directory Name

      |-- bin
          |-- edjfunction_example_cpp.wasm
      |-- build
          |-- lib.d
          |-- lib.o
          |-- serverless_function.d
          |-- serverless_function.o
      |-- src
          |-- lib.cpp
          |-- serverless_function.cpp
      |-- edjconfig.yaml
      |-- LICENSE
      |-- Makefile

      Where each function directory consists of the following subdirectories:

    • bin/ — Saves the compiled WASM executable of the example application, which is generated when compiling the function

    • build/ — Contains the intermediate object files of the example application, which is generated when compiling the function

    • src/ — Contains the source code of the example application

  3. Deploy the function: