Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't load package: package main #40313

Closed
fengxinming opened this issue Jul 20, 2020 · 3 comments
Closed

can't load package: package main #40313

fengxinming opened this issue Jul 20, 2020 · 3 comments

Comments

@fengxinming
Copy link

What version of Go are you using (go version)?

$ go version go1.14.6 darwin/amd64

Does this issue reproduce with the latest release?

Code

package main

/*
#include <stdio.h>

int getNumber() {
    return 1;
}
*/
import "C"

import (
	"syscall/js"
)

func main() {
	num := C.getNumber()
	console := js.Global().Get("console")
	console.Get("log").Invoke(1)
}

Build

GOOS=js GOARCH=wasm go build -o static/main.wasm main.go

Error

can't load package: package main: build constraints exclude all Go files in /Users/jesse/workspace/hello-vc/test09

What operating system and processor architecture are you using (go env)?

Switched to branch 'dev/1.4.0'
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jesse/Library/Caches/go-build"
GOENV="/Users/jesse/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jesse/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dq/05143lls7wl6r50lhh9p52y80000gp/T/go-build545878115=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was going to compile the go file to a wasm file, but it showed error.

What did you expect to see?

the go file will be compiled to a wasm file

What did you see instead?

can't load package: package main: build constraints exclude all Go files in /Users/jesse/workspace/hello-vc/test09
@cherrymui
Copy link
Member

js/wasm doesn't support cgo. You cannot build a cgo program for wasm.

@bcmills
Copy link
Contributor

bcmills commented Jul 20, 2020

Note that files that import "C" have an implicit cgo build constraint.

That said, the compiler's error message could be better when compiling with CGO_ENABLED=1 for js/wasm.

example.com$ GOOS=js GOARCH=wasm go build
package example.com: build constraints exclude all Go files in /tmp/tmp.MKI8rv27eJ/example.com

example.com$ GOOS=js GOARCH=wasm go env CGO_ENABLED
0

example.com$ GOOS=js GOARCH=wasm CGO_ENABLED=1 go build
# runtime/cgo
unknown ptrSize for $GOARCH "wasm"

@bcmills
Copy link
Contributor

bcmills commented Jul 20, 2020

Duplicate of #24068

@bcmills bcmills marked this as a duplicate of #24068 Jul 20, 2020
@bcmills bcmills closed this as completed Jul 20, 2020
@golang golang locked and limited conversation to collaborators Jul 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants