windows 环境 使用emcc 导出.wasm
extern “C” 大概意思是在C++ 中兼容C 或者用C 去解释/编译下面
#include <stdio.h>
#include <math.h>
int main() {
printf("hello, world \n");
return 0;
}
extern "C" {
int int_sqrt(int x) {
return sqrt(x); // math.h 中开平方的方法
}
}
cmd 中执行命令
test.cpp -s EXPORTED_FUNCTIONS="['_int_sqrt','_main']" -o test.js
为什么要记录,因为踩了坑吧
test.cpp -s EXPORTED_FUNCTIONS='["_int_sqrt", "_main"]' -o test.js
区别就在于引号的区别吧
本文介绍了如何在Windows环境下利用emcc将C++代码转换为WebAssembly(WASM),通过externC实现C/C++兼容,并通过调整EXPORTED_FUNCTIONS参数来导出函数。作者分享了一个包含数学函数sqrt的简单示例及遇到的问题
1079

被折叠的 条评论
为什么被折叠?



