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?