You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 08:48:02