The function exported by Emscripten cannot be imported

21 Views Asked by At

I tried importing functions from main.cpp to test.js.

main.cpp:

#include <cstdio>
#include <emscripten/emscripten.h>

using namespace std;

int myfunc() {
    // Code
    return num;
}

int main() {
    return 0;
}

shell command:

./emcc main.c

This command generates two files, a.out.wasm and a.out.js.

I try to call myfunc() function in test.js

test.js:

import { myFunc } from "a.out.js";

myFunc();

then run it:

SyntaxError: The requested module 'a.out.js' does not provide an export named 'myFunc'

When I checked the a.out.js file, I found that there was indeed no export statement。

Only this sentence is related to this function。

var _myfunc = Module['_myfunc'] = createExportWrapper('myfunc');

How to solve this problem? How can I import the function into test.js ?

0

There are 0 best solutions below