emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.67k stars 3.29k forks source link

Error While creating hello world with cout in c++ #22401

Open rggaur789 opened 1 month ago

rggaur789 commented 1 month ago

Hi,

I have tried the below simple c++ code

#include <iostream>

int main() {
    std::cout << "Hello World!\n";
    return 0;
}

with command emcc main.cpp -o file.wasm -s STANDALONE_WASM

and wasmtime file.wasm

but I am getting

Error: failed to run main module `file.wasm`

Caused by:
    0: failed to instantiate "file.wasm"
    1: unknown import: `env::_tzset_js` has not been defined

I am using emscripten and wasmtime latest versions. Can you please help what I am doing wrong here?

kripken commented 1 month ago

I believe this was fixed in #22316. That is not yet in a release, but you can use a tip of tree build, emsdk install tot.

rggaur789 commented 1 month ago

@kripken , also File handling will also work fine if I will use tip of tree build ?

kripken commented 1 month ago

@rggaur789 File handling support in standalone mode is pretty limited atm. There is some work on that here, but it has not landed: https://github.com/emscripten-core/emscripten/pull/18285