Tag Archives: go build

Go build error after MacOS Monterey system upgrade [How to Solve]

error

/usr/local/Cellar/go/1.16.3/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

Solution

xcode-select --install

If you still can’t

sudo xcode-select --reset

Go build cannot find package Error [How to Solve]

go env key data are as follows
GOPATH="/home/zzy/goProject"
GOROOT="/usr/local/go"

The project directory is like this

goProject
├── bin
├── pkg
└── src
    └── go_learn
            └── day01
                ├── hello
                │   ├── hello
                │   └── hello.go
                └── str_type
                    ├── str.go
                    └── world.go
hello.go my code is like this
package main

import (
    "fmt"
    "go_learn/day01/str_type/world"    ## This sentence imports packages and keeps reporting errors
)
func main()  {
    fmt.Print("hello world")
    test()
}

The

world.go code is like this
package main

import "fmt"

func test()  {
    fmt.Print("LALALALA")

}
go build reports an error like this
$ go build
hello.go:5:2: cannot find package "go_learn/day01/str_type/world" in any of:
        /usr/local/go/src/go_learn/day01/str_type/world (from $GOROOT)
        /home/zzy/goProject/src/go_learn/day01/str_type/world (from $GOPATH)

finally solved! A very low problem. It is estimated that beginners will make

Just change the content of the world.go file

package  world  # It's a file, not a package, don't import main

import "fmt"

# The function name is capitalized so you can reference the function outside
func Test()  {
    fmt.Println("lll")
    
}

 

Go build Error: cannot find package “fmt” in any of [How to Solve]

0. The project codes are as follows: 

The project code is written in gopath/SRC/Demo1/main/main.go

The go build command is executed under the gopath directory

1. The screenshot of error report is as follows: 2

Error reason: the wrong configuration of the root is caused by the FMT package in the error message. It points to F:: (go/bin/SRC) FMT, which indicates that our root is configured as the F:: (go/bin) directory. By default, go goes to the root/SRC directory to find the package directly introduced in our code

2. The solution is to modify the root and change the root to F: 2

After modification, recompile it