![](/img/trans.png)
[英]How to use the .js and .wasm artifacts emitted by Emscripten and Embind?
[英]how to Embind multiple Cpp files in Emscripten Compiler?
我在 Main.cpp 文件中調用了兩個 cpp 文件,此代碼將從 ams.js 文件中調用。 我使用 Embind Compiler 從 js 調用
這是我的示例代碼:
類.h
class CLASS{
public:
int VARIABLE;
void FUNCTION();
};
類.cpp
#include "CLASS.h"
void CLASS::FUNCTION()
{
VARIABLE = 5;
std::cout << "out : "+VARIABLE << std::endl;
}
主程序
#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);
}
編譯:
emcc --bind Main.cpp -o main.js
在 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();
輸出錯誤:
main3.js:2780 Uncaught BindingError: Tried to invoke ctor of MyClass with invalid number of parameters (0) - expected (1) parameters instead!
幫我解決這個問題
使用單獨編譯。
emcc --bind -c class.cpp
emcc --bind -c main.cpp
emcc --bind class.o main.o -o main.js
但是 BindingError 是由new Module.MyClass();
引起的new Module.MyClass();
, 試試new Module.MyClass(123);
.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.