Skip to content

undefined: wasmtime.Wat2Wasm on windows and macos (darwin) #240

@Eyzic

Description

@Eyzic

When compiling with GOOS and GOARCH flags, compilation fails when GOOS is windows or darwin, but succeeds when it is linux.
I am running the go build command from linux (tried both fedora-41 locally and ubuntu-latest through build pipeline).

Issue

Running:
GOOS=windows GOARCH=amd64 go build -o test
GOOS=darwin GOARCH=amd64 go build -o test

Produces:
undefined: wasmtime.Wat2Wasm

Conditions

In the file it complains about, there is an import "github.com/bytecodealliance/wasmtime-go/v29" and a function call wasmBytes, err := wasmtime.Wat2Wasm(wat).

Not an issue

Running:
GOOS=linux GOARCH=amd64 go build -o test

Works fine without any compilation error.


Seems very strange to me that GOOS would affect something becoming undefined, so I'm suspecting something might be wrong? If there is an explanation for this or I am missing something, then perhaps it would be good to add that to the readme file. If I am the only one with this issue, do let me know.

Workaround (In case someone else has this issue)

I managed to work around it by not cross-compiling and adding flag CGO_ENABLED=1. That made it work of macos.
For windows I also needed to download MinGW and set CC=x86_64-w64-mingw32-gcc and CXX=x86_64-w64-mingw32-g++

Leaving that here in case it helps anybody else.

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