Compile two .cpp files to webassembly.
I have two cpp files, Main.cpp and TestClass.cpp and one .h file
TestClass.h.
When i compile files
emcc -Os Main.cpp TestClass.cpp -s WASM=1 -s SIDE_MODULE=1 -s
ALLOW_MEMORY_GROWTH=1 -o ns.wasm
and run WebAssembly.instantiateStreaming i get error:
Error: Uncaught (in promise): LinkError: WebAssembly.instantiate(): Import
#0 module="env" function="__stack_pointer"
error: imported mutable global must be a WebAssembly.Global object
If i change #include "TestClass.h" to #include "TestClass.cpp" in Main.cpp
and compile with
emcc -Os Main.cpp -s WASM=1 -s SIDE_MODULE=1 -s ALLOW_MEMORY_GROWTH=1 -o
ns.wasm
then WebAssembly.instantiateStreaming works!
I want use #include "TestClass.h" in Main.cpp. What am I doing wrong ?
Thanks.
-------------------------------------
Main.cpp
-------------------------------------
#include "TestClass.h"
#include <emscripten.h>
using namespace std;
extern "C"
{
int EMSCRIPTEN_KEEPALIVE testwasm()
{
TestClass tc;
return tc.Test();
}
}
int main()
{
}
-------------------------------------
TestClass.h
-------------------------------------
#pragma once
class TestClass
{
public:
int Test();
};
-------------------------------------
TestClass.cpp
-------------------------------------
#include "TestClass.h"
int TestClass::Test()
{
return 100;
}
-------------------------------------
Code i use to load webassembly
-------------------------------------
var importObject = {
module: {},
env: {
memory: new WebAssembly.Memory({initial: 256, maximum: 256})
}
(async () => {
const fetchPromise = fetch('ns.wasm');
const { instance } = await WebAssembly.instantiateStreaming(fetchPromise,
importObject);
const result = instance.exports.testwasm as CallableFunction;
...
})();
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/emscripten-discuss/653fd15a-31c1-40f0-a659-4dcd9a6fddd9n%40googlegroups.com.