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?
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"]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With