extern“C”无法识别std :: string.
你可能想试试这个:
TEST.CPP
#include
#include
extern "C" int stringLen(char* p)
{
return strlen(p);
}
使用以下命令编译cpp代码:
emcc Test.cpp -s EXPORTED_FUNCTIONS="['_stringLen']
示例测试代码:
的test.html
Hello World !var strLenFunction = Module.cwrap('stringLen', 'number', ['string']);
var len1 = strLenFunction("hi."); // alerts 3
alert(len1);
var len2 = strLenFunction("Hello World"); // alerts 11
alert(len2);