I am currently trying to compile C to wasm and use it on a website. But I have had zero luck so far.
What I currently have is the following C source file:
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE
int sum(int a, int b) {
return a + b;
}
I compile it using the following emscripten command:
emcc test.c -o test.js -s EXPORTED_FUNCTIONS="['_sum']" -sMODULARIZE
This produces test.wasm and test.js.
Then, I have the following html code:
<html>
<!--...-->
<body>
<script type="module">
var _import = import('test.js');
_import.then((instance) => {
console.log(instance._sum());
});
</script>
</body>
</html>
When I start up a development server, I get the following error in the console:
Uncaught (in promise) TypeError: instance._sum is not a function
<anonymous> http://localhost:8000/:7
promise callback* http://localhost:8000/:6
I also tried instance.sum and instance.ccall('sum'), both with the same result.
I have no clue at this point what I am doing wrong.