emscripten-core / emscripten-core/emscripten

native function `stackSave` called before runtime initialization

Open
#14,609 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

When learning emscripten, I encountered the following problems. When fetching the ccall function, I encountered the following error: `native function `stackSave` called before runtime initialization`
C++ code as follow:
```c++
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
extern "C" {
int run (const string args) {
string arg;
bool argf = false;
for (int i = 0; i < args.length(); i++) {
if (args[i] == ' ') {
if (argf) {
cout << (arg + "\n") << endl;
argf = false;
arg = "";
}
} else {
argf = true;
arg = arg + args[i];
}
}
return 0;
}
}

int main() {
cout << "hello, world!\n" << endl;
return 0;
}
```
Run the script as follows:
```
emcc ./emscripten.cpp \
-O0 \
-s NO_EXIT_RUNTIME=1 \
-s WASM=0 \
-s EXPORTED_FUNCTIONS='["_run","_main"]' \
-s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","FS"]' \
-s NODERAWFS=0 \
-o emscripten.js
```
It is used in JS as follows
```js
const emscripten = require("./emscripten");
emscripten.ccall('run', '', ['string'], ["--style=ansi /file.v"]);
```
The environment:
WSL2: ubuntu 18.04
emsdk: 2.0.24
Looking forward to your help and advice, any answer you may give will be helpful to me.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.