Home  >  Article  >  Backend Development  >  What should I do if golang cannot find the package?

What should I do if golang cannot find the package?

angryTom
angryTomOriginal
2020-02-15 16:01:543862browse

What should I do if golang cannot find the package?

What should I do if golang cannot find the package

Problem description

Usego buildCompile* The .go program cannot find the package. The window information is as follows:

$GOPATH>go build stacker.go
stacker.go:18:2: cannot find package “stack” in any of:
D:\Go\src\stack (from $GOROOT)
$GOPATH\src\stack (from $GOPATH)
$GOPATH>go version
go version go1.11.2 windows/amd64

Ideas to solve the problem

It seems that the GOPATH environment variable is not set correctly.

Problem Analysis

go build prompts that the corresponding library file cannot be found in the src stack directory.

The package content of stacker.go is roughly as follows

package main
import (
"fmt"
"stacker/stack"
"strings"
)

So try to modify $GOPATH to the same level directory as src, and then use go build stacker. You can find the corresponding stack package normally by compiling go.

Problem Summary

The go compiler will search for the package in the src directory in the current directory by default. If there is no src directory, the compiler cannot find the corresponding package.

For more golang knowledge, please pay attention to the golang tutorial column on the PHP Chinese website.

The above is the detailed content of What should I do if golang cannot find the package?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn