运行
emcc -s WASM=1 -O3 -o program.js program.cpp --js-library library.js
返回
warning: unresolved symbol: _Z6funcNamev
program.js
#include <emscripten/emscripten.h>
#include <stack>
// 定义数组大小
#define N 100
// 防止 C++ 函数名被 Mangling
#ifdef _cplusplus
extern "C" {
#endif
// 预置函数,暴露给 JS 进行处理
extern void checku ();
void EMSCRIPTEN_KEEPALIVE abc () {
char a[] = "username";
checku();
}
#ifdef _cplusplus
}
#endif
library.js
mergeInto(LibraryManager.library, {
checku: function() {
console.log(123)
}
});
笔误,踩了一个大坑。
#ifdef _cplusplus
extern "C" {
#endif
其实是 __cplusplus 前面两个下划线
#ifdef __cplusplus
extern "C" {
#endif
添加这个判断防止 C++ 函数名被 Mangling.