首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用wasmtime运行wasm文件时未能调用函数

使用wasmtime运行wasm文件时未能调用函数
EN

Stack Overflow用户
提问于 2019-10-17 02:34:20
回答 1查看 594关注 0票数 1

Mozilla共享WASI以及如何使用Wasmtime来运行。是他们博客帖子中的文件。他们演示的编程语言是Rust

代码语言:javascript
复制
#[wasm_bindgen]
pub fn render(input: &str) -> String {
    let parser = Parser::new(input);
    let mut html_output = String::new();
    html::push_html(&mut html_output, parser);
    return html_output;
}

但是,我想在C中做同样的事情。

我下载了瓦西,并尝试用Clang构建一个“hello world”程序。

我在test.c中创建了两个函数

代码语言:javascript
复制
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int foo1()
{
    printf("Hello foo1()\n");
    return 0;
}

int foo2(char* filename)
{
    printf("Hello foo2()\n");
    printf("filename is %s\n", filename);
    return 0;
}

使用命令构建它:

代码语言:javascript
复制
clang --target=wasm32-wasi --sysroot=/mnt/d/code/wasi-libc/sysroot test.c -o test.wasm -nostartfiles -Wl,--no-entry,--export=foo1,--export=foo2

运行wasm文件来调用函数:

代码语言:javascript
复制
$ wasmtime test.wasm --invoke foo1
Hello foo1()
warning: using `--render` with a function that returns values is experimental and may break in the future
0

$ wasmtime test.wasm --invoke foo2 "hello"
warning: using `--render` with a function that takes arguments is experimental and may break in the future
error: failed to process main module `test.wasm`
    caused by: invalid digit found in string

我未能使用输入参数调用函数。

铁锈和C有什么区别?Rust目前是构建wasm文件的唯一方法吗?

EN

回答 1

Stack Overflow用户

发布于 2019-10-19 16:24:22

不同之处在于,Rust工具链对接口类型有实验性的支持,而对于C则不存在,不幸的是。#[wasm_bindgen]位于render函数之上,它将render转换为一个带有接口类型绑定的函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58424072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档