添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

So I wanted to compile a simple c++ file into js and run it in a web browser. The steps I took (on windows):

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

The last command printed:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.39.15
clang version 11.0.0 "

Then I tried to compile "hello world" in main.cpp file that looks like:

#include <iostream>
#include <emscripten.h>
int main()
    std::cout<< "hello world!" << std::endl;
    return 0;

So then in test folder I used command:

em++ main.cpp -o 1.html

which printed:

cache:INFO: generating system library: libcompiler_rt.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libcompiler_rt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc-wasm.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libc-wasm.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc++-noexcept.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libc++-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc++abi-noexcept.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libc++abi-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libdlmalloc.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libdlmalloc.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libpthread_stub.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libpthread_stub.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc_rt_wasm.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libc_rt_wasm.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libsockets.a... (this will be cached in "C:\Users\x\.emscripten_cache\wasm\libsockets.a" for subsequent builds)
cache:INFO:  - ok

and as output i got the following files: 1.html, 1.js, 1.wasm

And when I open 1.html I see these errors:

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

I also tried it on linux, but exactly the same errors appear. Older versions of the emscripten SDK don't work either.

Any hints?

This error can also occur if you only have the html folder in the web server's directory. The associated .wasm file must be in the web server's folder.

So for the hello_world example, copy the hello.html file AND the hello.wasm file.

If testing within the Chrome Browser, you can open the Developer Tools panel and chose the console tab. Refresh the page and observe any error messages.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.