You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过TinyGo导出含空格名称的Wasm方法?

问题

尝试用TinyGo导出名称包含空格的Wasm函数失败,具体情况:

  • 源码示例:
//go:export canister_query get
func get() uint32 {
    return 0
}
  • 构建命令:
tinygo build -o counter.wasm -target=wasm -scheduler=none -no-debug -panic=trap ./main.go
  • 现象:将生成的Wasm转为Wat后,未找到名称为canister_query get的导出;改用下划线替换空格(//go:export canister_query_get)后,导出成功。
解决方法

修改导出注释,给带空格的导出名称加上双引号即可:

//go:export "canister_query get"
func get() uint32 {
    return 0
}

重新执行原构建命令编译后,转换为Wat就能看到预期的导出:

(export "canister_query get" (func $canister_query_get))

原理:TinyGo的//go:export指令支持用双引号包裹包含特殊字符(如空格)的导出名称,编译器会直接使用引号内的完整字符串作为Wasm导出名,不会对空格进行转义或替换。

内容的提问来源于stack exchange,提问作者Abel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 15:32:05