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

cmd/go, cmd/cgo: “ build constraints exclude all Go files“ error #39398

Closed
lbbxsxlz opened this issue Jun 4, 2020 · 2 comments
Closed

cmd/go, cmd/cgo: “ build constraints exclude all Go files“ error #39398

lbbxsxlz opened this issue Jun 4, 2020 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@lbbxsxlz
Copy link

lbbxsxlz commented Jun 4, 2020

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

$ go version

go version go1.14.4 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env


GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/lbbxsxlz/.cache/go-build"
GOENV="/home/lbbxsxlz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/lbbxsxlz/workspace/GO"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/lbbxsxlz/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/lbbxsxlz/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build451549208=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import "C"
import (
        "debug/elf"
        "errors"
        "io/ioutil"
        "log"
)

func CreateUuidFile(progfile, sectionname, filename string)(error) {
        ef, err := elf.Open(progfile)
        if err != nil {
                log.Printf("open elf fail \n")
                return errors.New("open elf fail \n")
        }
        defer ef.Close()

        section := ef.Section(sectionname)
        if section == nil {
                log.Printf("get uuid section fail \n")
                return errors.New("get uuid section fail \n")
        }

        data, err:= section.Data()
        if err != nil {
                log.Printf("get uuid data fail \n")
                return errors.New("get get uuid data fail \n")
        }

        err = ioutil.WriteFile(filename, data, 0666)
        if err != nil {
                log.Printf("WriteFile data fail \n")
                return errors.New("WriteFile data fail \n")
        }

        ef.Close()
        return nil
}

func main() {
        if err := CreateUuidFile("/home/31770/sonia", ".uuid", "sonia-uuid.txt"); err != nil {
                log.Fatal("CreateUuidFile fail")
        }
}

What did you expect to see?

"GOOS=linux GOARCH=arm64 go build -o elfTest_arm64 elfTest.go" build no errors

What did you see instead?

can't load package: package main: build constraints exclude all Go files in /home/lbbxsxlz/workspace/GO

"GOOS=linux GOARCH=arm64 go build -o elfTest_arm64 elfTest.go" build fail
"GOOS=linux GOARCH=arm go build -o elfTest_arm elfTest.go" build fail

@cherrymui
Copy link
Member

Try setting CGO_ENABLED=1, and CC to a C cross compiler. For cross-compilation, cgo is disabled by default. You need to enable it explicitly. And you'll need a C cross compiler.

debug/elf is probably not related.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 4, 2020
@odeke-em odeke-em changed the title use "debug/elf" can not build in GOOS=linux GOARCH=arm/arm64 cmd/go, cmd/cgo: “ build constraints exclude all Go files“ error Jun 5, 2020
@lbbxsxlz
Copy link
Author

lbbxsxlz commented Jun 6, 2020

Try setting CGO_ENABLED=1, and CC to a C cross compiler. For cross-compilation, cgo is disabled by default. You need to enable it explicitly. And you'll need a C cross compiler.

debug/elf is probably not related.

Thank you!

@lbbxsxlz lbbxsxlz closed this as completed Jun 6, 2020
@golang golang locked and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants