when import "golang.org/x/net/route"

it tells "build constraints exclude all Go files in go/src/golang.org/x/net/routego"

I am using VSCode editor on Windows/Linux

I searched online and didn't see a solution to the similar problem

package mainimport ("golang.org/x/net/route"){rib, _ := route.FetchRIB(0, route.RIBTypeRoute, 0)messages, err := route.ParseRIB(route.RIBTypeRoute, rib)}
13

Best Answer


I had this problem in Goland (with source code on WSL2 and Goland on win).

I was able to solve it with

go clean -modcache

Subsequent build put everything in order again.

Prompts are a useful tool for generating creative content. One interesting prompt is 'build constraints exclude all go files in'.

Build constraints are a way to control which files are included or excluded from the build process in Go programming language. When all the go files are excluded, it means that the build process will not generate any output.

This prompt can be used to explore the reasons why all go files might be excluded from the build process. It could be due to specific build constraints set in the code, or it could be an error or misconfiguration.

By understanding the possible scenarios and reasons behind this situation, developers can troubleshoot and resolve any build issues they might encounter. It also helps to ensure that the build process is optimized and efficient.

We met the same error under Goland, and it could be solved in this way

If you want to set GOOS = linux under Mac, just add this line in the header of file // +build linux,amd64,go1.15,!cgo which means we declare that this file is for the target system that has the following requirements: Linux, the AMD64 architecture, the 1.15 Go version, and no CGO support.


Update 08/04/2022

After go 1.17. The go command now understands //go:build lines and prefers them over // +build lines. The new syntax uses boolean expressions, just like Go, and should be less error-prone. Here are some more details

// go:build (darwin && cgo) || linux// +build darwin,cgo linux

My issue was that I had a stray import "C" in my code and I was compiling with CGO_ENABLED=0. This problem was hard to find because IntelliJ collapses all the imports into one statement.

try to remove folder x in go/src/golang.org/

In my case I just by an accident replaced original code by test file, it was containing the following comments:

//go:build unittest// +build unittest

I fixed the issue by simply doing Invalidate Caches under File Tab.

If you have a dependency requiring cgo (which includes x/net by default), you will get this error if your system does not have a C compiler. Can be easily fixed by installing gcc.

This error seems to present itself rather ambiguously.

In my case, my project uses CGO, and this error manifests when CGO_ENABLED=0 in the environment, which is solved by unsetting this env var, or setting CGO_ENABLED=1

In my case it appears the go get failed and the folder referenced in GOPATH was empty. Check your library folder which is complaining here. here

In my case, after trying the go clean -modcache solution, I also had to restart Goland before it stopped complaining about the build constraints.

"build constraints exclude all Go files in go/src/golang.org/x/net/routego"In Intellij :

  1. Navigate to the folder in the project explorer
  2. Right click -> Mark folder as not excluded.

If you get error build constraints exclude all Go files in ... with go get command, please specify the path as follows

Error:

$ go get {HOST}/platform/be-photo

Success:

$ go get {HOST}/platform/be-photo/external/client