Skip to content

No compiled main function from file called  #212

Description

@arejula27

I am trying to run a program compiled into wasm from go. In Rust exists a guide for it, however, I have not found it in Go.

I have created the following hello.go file

package main

import "fmt"

func main() {
	fmt.Println("Hello, World!")
}

And compile to hello.wasm using tiny go. Using wasmtime hello.wasm the correct output is expected.
Now i want to call it from my go code:

package main

import (
	"log"

	"github.com/bytecodealliance/wasmtime-go"
)

func main() {

	store := wasmtime.NewStore(wasmtime.NewEngine())

	
	module, err := wasmtime.NewModuleFromFile(store.Engine, "/home/arejula27/workspaces/go-lab/wasm/hello.wasm")
	if err != nil {
		panic(err)
	}
	linker := wasmtime.NewLinker(store.Engine)

	linker.DefineModule(store, "", module)
	hello, err := linker.GetDefault(store, "")
	if err != nil {
		panic(err)
	}
	_, err = hello.Call(store)
	if err != nil {
		log.Fatal(err)
	}

}

With this code, no output is generated. Do you know how I can do it correctly?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions