Problems with emscripten (WebAssembly)
Problems with emscripten (WebAssembly)
所以我想将一个简单的c ++文件编译成js并在Web浏览器中运行它。我采取的步骤(在窗户上(:
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
emsdk install latest
emsdk activate latest
emsdk_env.bat --global
emsdk update-tags
emcc -v
打印的最后一个命令:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.39.15
clang version 11.0.0 "
然后我尝试在main.cpp文件中编译"hello world",如下所示:
#include <iostream>
#include <emscripten.h>
int main()
{
std::cout<< "hello world!" << std::endl;
return 0;
}
所以在测试文件夹中我使用了命令:
em++ main.cpp -o 1.html
其中打印:
cache:INFO: generating system library: libcompiler_rt.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibcompiler_rt.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libc-wasm.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibc-wasm.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libc++-noexcept.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibc++-noexcept.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libc++abi-noexcept.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibc++abi-noexcept.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libdlmalloc.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibdlmalloc.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libpthread_stub.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibpthread_stub.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libc_rt_wasm.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibc_rt_wasm.a" for subsequent builds)
cache:INFO: - ok
cache:INFO: generating system library: libsockets.a... (this will be cached in "C:Usersx.emscripten_cachewasmlibsockets.a" for subsequent builds)
cache:INFO: - ok
作为输出,我得到了以下文件:1.html
、1.js
、1.wasm
当我打开1.html
时,我看到这些错误:
both async and sync fetching of the wasm failed
RuntimeError: abort(both async and sync fetching of the wasm failed) at jsStackTrace@file:///E:/emscripten/emsdk/test/1.js:1952:17
stackTrace@file:///E:/emscripten/emsdk/test/1.js:1969:16
abort@file:///E:/emscripten/emsdk/test/1.js:1728:44
getBinary@file:///E:/emscripten/emsdk/test/1.js:1800:10
getBinaryPromise/<@file:///E:/emscripten/emsdk/test/1.js:1822:13
getBinaryPromise@file:///E:/emscripten/emsdk/test/1.js:1821:10
instantiateArrayBuffer@file:///E:/emscripten/emsdk/test/1.js:1865:12
instantiateAsync@file:///E:/emscripten/emsdk/test/1.js:1892:14
createWasm@file:///E:/emscripten/emsdk/test/1.js:1908:3
@file:///E:/emscripten/emsdk/test/1.js:4990:11
我也在 Linux 上尝试过,但出现了完全相同的错误。旧版本的 emscripten SDK 也不起作用。
有什么提示吗?
使用file://
的问题,我认为你需要运行服务器并使用http://
。 请参阅:https://emscripten.org/docs/getting_started/FAQ.html#faq-local-webserver。 还有:https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html
如果 Web 服务器的目录中只有 html 文件夹,也会发生此错误。 关联的 .wasm 文件必须位于 Web 服务器的文件夹中。
因此,对于hello_world示例,请复制 hello.html 文件和 hello.wasm 文件。
如果在 Chrome 浏览器中进行测试,您可以打开"开发人员工具"面板,然后选择控制台标签。 刷新页面并观察任何错误消息。
相关文章:
- WebAssembly include OpenCV
- 用户控制从 c++ 到 java 脚本的 Webassembly 访问调用
- 如何从WebAssembly模块检测浏览器信息?
- 在C++中序列化浮点数/双精度,编译为 WebAssembly
- 没有 Emscripten,如何使用标准库编译C++到 WebAssembly
- 我可以在不使用Qt for Webassembly的情况下使用Emscripten编译Qt吗?
- Problems with emscripten (WebAssembly)
- 使用导入的函数从嵌入式v8调用webassembly
- Webassembly from Javascript
- 是否可以使用 Webassembly 从磁盘读取文件?
- 如何查看Tibco EMS独享队列是否有活跃消费者?
- webassembly and get_nprocs()
- 如何使用 emscripten 使用 SDL 将纹理加载到 WebAssembly 项目中
- Emscripten 和 boost 库:如何为 WebAssembly 编译现有项目
- webAssembly有标准的基准测试吗?
- 从 WebAssembly 运行外部应用程序
- 如何将 WebAssembly 编译成常规汇编/本机代码(或 Cpp 等)
- 如何将指向本地结构的指针转换为WebAssembly
- 键盘输入不与WebAssembly和Emscripten配合使用
- 你能用javascript来停止WebAssembly中当前运行的c++吗?