Setup your C/C++ environment
To build C applications that use the Wasmer runtime as a host for guest Wasm modules, you will need a C compiler installed (clang or gcc, for example). Check the compiler installation instructions here.
Starting with Wasmer 1.0 all the releases ship with the required libraries and headers to use Wasmer from C and C++.
If you haven't yet, let's install Wasmer:
1
curl https://get.wasmer.io -sSfL | sh
Copied!
Once Wasmer is installed, you can get the pkg-config easily:
1
$ wasmer config --pkg-config
2
prefix=/Users/USER/.wasmer
3
exec_prefix=/Users/USER/.wasmer/bin
4
includedir=/Users/USER/.wasmer/include
5
libdir=/Users/syrus/.wasmer/lib
6
​
7
Name: wasmer
8
Description: The Wasmer library for running WebAssembly
9
Version: 2.0.0
10
Cflags: -I/Users/USER/.wasmer/include/wasmer
11
Libs: -L/Users/syrus/.wasmer/lib -lwasmer
Copied!

Manual Installation

Download Wasmer from Wasmer releases page. Depending on your system, you will need to download:
    Linux: wasmer-linux-amd64.tar.gz or wasmer-linux-aarch64.tar.gz
    macOS: wasmer-darwin-amd64.tar.gz or wasmer-darwin-arm64.tar.gz
    Windows: wasmer-windows.tar.gz
Once you have downloaded the framework, you can now extract its contents and set the WASMER_DIR environment variable to the path of the wasmer directory (this will be very useful when running the examples):
1
# Extract the contents to a dir
2
mkdir wasmer
3
tar -C wasmer -zxvf wasmer-*.tar.gz
4
​
5
export WASMER_DIR=$(pwd)/wasmer
6
​
7
# Update LD_LIBRARY_PATH to link against the libwasmer.so in the examples
8
export LD_LIBRARY_PATH=$WASMER_DIR/lib/:$LD_LIBRARY_PATH
Copied!
Note: You can also build the C-API from source.

Installing Clang/GCC

First, you can test if clang or gcc is installed already by running:
1
gcc --version
Copied!
If this command does not return the version, then see the following:

MacOS

gcc / clang is usually installed by default. However, if it is not, you can install gcc/clang by installing xcode-select on your mac.

Debian / Debian Based / Linux

To install gcc on a Debian based, you will want to run the following:
1
sudo apt-get install build-essential
Copied!
Gcc should be installable on your favorite linux distro as well. Please search for the correct command for your desired distribution.

Windows

To install gcc on Windows, you will probably want to install a GNU environment on windows. We suggest using MinGW.
1
gcc --version
2
​
3
# This should output: "ATTRIBUTIONS LICENSE bin include lib"
4
ls $WASMER_DIR
Copied!
If these commands work, The compiler and the Wasmer C API are successfully installed!
Next, let's take a look at some examples!
Last modified 4mo ago