I'm trying to create a simple example using MAIN_MODULE/SIDE_MODULE based on https://github.com/emscripten-core/emscripten/wiki/Linking#general-dynamic-linking but cannot make it work.
Here's my code:
main.c:
#include <stdio.h>
int side(int a);
int main()
{
printf("hello world %d\n", side(1));
}
side.c:
int side(int a)
{
return a + 1;
}
compile:
emcc side.c -s SIDE_MODULE=1 -o side.wasm
emcc main.c -s MAIN_MODULE=1 -o main.html
index.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var Module
= {
preRun: []
, postRun: []
, print: function (e) {
1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" "));
console.log(e);
}
, printErr: function (e) {
1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" "));
console.error(e)
}
};
Module.dynamicLibraries = ['side.wasm'];
</script>
<script async src="main.js"></script>
</body>
</html>
If I run it with python -m SimpleHTTPServer, I get the following errors:
(index):19 Assertion failed: undefined
printErr @ (index):19
abort @ main.js:33157
assert @ main.js:1074
removeRunDependency @ main.js:1984
(anonymous) @ main.js:2274
Promise.then (async)
instantiateArrayBuffer @ main.js:2272
(anonymous) @ main.js:2301
Promise.then (async)
(anonymous) @ main.js:2296
Promise.then (async)
instantiateAsync @ main.js:2288
createWasm @ main.js:2321
Module.asm @ main.js:2344
(anonymous) @ main.js:31495
(index):19 failed to asynchronously prepare wasm: abort(Assertion failed: undefined) at Error
at jsStackTrace (http://localhost:8000/main.js:1626:13)
at stackTrace (http://localhost:8000/main.js:1643:12)
at abort (http://localhost:8000/main.js:33163:44)
at assert (http://localhost:8000/main.js:1074:5)
at removeRunDependency (http://localhost:8000/main.js:1984:5)
at http://localhost:8000/main.js:2274:7
Any advice or guidance would be greatly appreciated!