i have two cpp files called in Main.cpp files this code to be called from ams.js files. im using Embind Compiler to call from js
here is my sample Code :
class.h
class CLASS{
public:
int VARIABLE;
void FUNCTION();
};
class.cpp
#include "CLASS.h"
void CLASS::FUNCTION()
{
VARIABLE = 5;
std::cout << "out : "+VARIABLE << std::endl;
}
Main.cpp
#include <emscripten/bind.h>
#include "CLASS.h"
using namespace emscripten;
class MyClass
{
public:
MyClass(int x)
: x(x)
{}
int getCharCount(std::string strKey)
{
CLASS a;
a.FUNCTION();
return 0;
}
private:
int x;
};
EMSCRIPTEN_BINDINGS(my_class_example) {
class_<MyClass>("MyClass")
.constructor<int>()
.function("getCharCount", &MyClass::getCharCount);
}
For Compiling :
emcc --bind Main.cpp -o main.js
Calling the Function in Render.js
var instance = new Module.MyClass();
if (instance){
var mainee = instance.getCharCount("hi")
console.log("Somrthing is There");
}else{
console.log("Somrthing Wrong");
}
instance.delete();
Output error:
main3.js:2780 Uncaught BindingError: Tried to invoke ctor of MyClass with invalid number of parameters (0) - expected (1) parameters instead!
help me to solve this issue
Use separate compilation.
emcc --bind -c class.cpp
emcc --bind -c main.cpp
emcc --bind class.o main.o -o main.js
But BindingError is caused by new Module.MyClass();
, try new Module.MyClass(123);
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.