c - 如何在 Emscripten 中从 MAIN_MODULE 正确加载 SIDE_MODULE?
问题描述
我正在尝试使用MAIN_MODULE/SIDE_MODULE
基于https://github.com/emscripten-core/emscripten/wiki/Linking#general-dynamic-linking的简单示例,但无法使其工作。
这是我的代码:
主.c:
#include <stdio.h>
int side(int a);
int main()
{
printf("hello world %d\n", side(1));
}
边.c:
int side(int a)
{
return a + 1;
}
编译:
emcc side.c -s SIDE_MODULE=1 -o side.wasm
emcc main.c -s MAIN_MODULE=1 -o main.html
索引.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>
如果我用 运行它python -m SimpleHTTPServer
,我会收到以下错误:
(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
任何建议或指导将不胜感激!
解决方案
推荐阅读
- c# - 从 XML 节点读取特定值
- c# - 映射页面路由后如何禁用pageName?
- django - 为 django-location-field 和 python3 安装 gdal 包
- xaml - 如何在 Xamarin.Forms 中居中图像而不拉伸它
- android - 无法解决android中的属性不兼容错误
- rabbitmq - 如果每条消息都将路由到主节点,为什么要在 RabbitMQ 节点集群(相同队列)前面放置负载均衡器?
- python - nodejs - python 文件未在生产中导出?
- node.js - textarea 和 input HTML 元素之间的安全区别?
- javascript - Javascript更新文本而不刷新页面
- c++ - 找到后更改类变量