使用emrun运行WebAssembly HelloWorld时出现网络错误异常,但Python静态服务器可正常运行的问题求助
使用emrun运行WebAssembly HelloWorld时出现网络错误异常,但Python静态服务器可正常运行的问题求助
我最近在学习WebAssembly,写了一个最简版的Hello World代码:
#include <emscripten.h> #include <stdlib.h> #include <stdio.h> int main() { printf("hello world"); }
我用emcc编译并尝试通过emrun运行,操作步骤如下:
- 编译命令:
emcc hello.c --emrun -o hello.html(执行后生成了hello.html、hello.js、hello.wasm三个文件) - 尝试1:
emrun --browser firefox hello.html - 尝试2:
emrun --browser firefox .
但这两种运行方式都会让浏览器抛出**"Uncaught DOMException: A network error occurred."**的异常。不过如果我换用Python的HTTP服务器来运行:python -m http.server,程序就能正常工作。
另外还有个细节:如果我把printf里的字符串末尾加上\n,改成printf("hello world\n"),就能看到输出内容(不加\n的话看不到输出),但那个网络错误异常还是会出现。我现在搞不懂这个异常到底会带来什么影响,有没有大佬能帮忙解答一下?
内容来源于stack exchange
相关产品推荐
相关产品推荐

