Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve EXTRA_EXPORTED_RUNTIME_METHODS exception when cmake used with emscripten?

Here found some similar question. However, with similar cmake file used, the exception thrown: RuntimeError: abort('cwrap' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)) at Error still exists when running the generated .js file.

The CMakefileLists.txt code:

cmake_minimum_required(VERSION 3.10)

project(solutions)

add_definitions("-s EXPORTED_RUNTIME_METHODS='[\"ccall\",\"cwrap\"]'")
add_definitions("-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\",\"cwrap\"]'")
#SET_TARGET_PROPERTIES(test PROPERTIES LINK_FLAGS "-s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']")

add_executable(test hello.cc)

set(CMAKE_EXECUTABLE_SUFFIX ".html")

The hello.cc code:

#include <emscripten.h>

extern "C" {
  double SquareVal(double val) {
    return val * val;
  }
}

int main() {
  EM_ASM({
    SquareVal = Module.cwrap('SquareVal', 'number', ['number']);
    var x = 12.5;
    alert('Computing: ' + x + ' * ' + x + ' = ' + SquareVal(x));
  });
}

I think in these way, the cwrap was already added to EXTRA_EXPORTED_RUNTIME_METHODS . How to solve this?

like image 595
heLomaN Avatar asked Sep 01 '25 03:09

heLomaN


1 Answers

This is the correct way to export methods:

emcc wrapping.c -o wrapping.js -s NO_EXIT_RUNTIME=1 -s 'EXPORTED_RUNTIME_METHODS=["ccall"]' 

EXTRA_EXPORTED_RUNTIME_METHODS is ok, but is going to be deprecated:

emcc wrapping.c -o wrapping.js -s NO_EXIT_RUNTIME=1 -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall"]' 
like image 164
Leandro Ariel Avatar answered Sep 02 '25 15:09

Leandro Ariel