Compiling C++ with external library to Wasm using Wasmer

Viewed 328

I'm trying to compile C++ file linked with external library using Wasmer.

I built external library using:

git clone -b main https://github.com/open-quantum-safe/liboqs.git
cd liboqs
mkdir build && cd build
wasimake cmake -GNinja ..
wasimake ninja

As a result I've got liboqs.a library which I want to reuse in code that I'm trying to compile to Wasm. Here is the code:

#include <stdio.h>
#include <oqs/oqs.h>

int main(void)
{
   uint8_t public_key[OQS_KEM_frodokem_640_aes_length_public_key];
   uint8_t secret_key[OQS_KEM_frodokem_640_aes_length_secret_key];

   OQS_STATUS rc;
   rc = OQS_KEM_frodokem_640_aes_keypair(public_key, secret_key);

   printf("%d\t", (int)rc);

   return 0;
}

Compiling file with this command:

wasicc -I ../../build/include "liboqs.a" "example.cpp" -o example.wasm

../../build/include - path to build folder of external library.

I'm getting this error:

wasm-ld: error: liboqs.a(rand.c.o): undefined symbol: __memory_base

I don't understand what does this error mean and what can be the reason of it.

1 Answers

Not sure if this helps, but I was able to build this C file below:

cd liboqs
mkdir build && cd build
cmake -GNinja ..
wasicc \
  -o example.wasm \
  -I liboqs/build/include \
  example.c
#include <stdio.h>
#include <oqs/oqs.h>

int main(void)
{
  uint8_t public_key[OQS_KEM_frodokem_640_aes_length_public_key];
  uint8_t secret_key[OQS_KEM_frodokem_640_aes_length_secret_key];

  return 0;
}
Related