//main.cc:
#ifndef EM_PORT_API
# if defined(__EMSCRIPTEN__)
# include <emscripten.h>
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype EMSCRIPTEN_KEEPALIVE
# else
# define EM_PORT_API(rettype) rettype EMSCRIPTEN_KEEPALIVE
# endif
# else
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype
# else
# define EM_PORT_API(rettype) rettype
# endif
# endif
#endif
#include <stdio.h>
#include <string>
using namespace std;
EM_PORT_API(string) show_me_the_answer() {
return "42--aa";
}
int main() {
printf("你好,世界!\n");
return 0;
}
// html:
console.log(Module._show_me_the_answer());
程序运行结果没用解析为 42--aa, 而是 undefined .