What should I do if golang cannot find the package?

angryTom
Release: 2020-02-15 16:01:54
Original
3771 people have browsed it

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
Copy after login

Ideas to solve the problem

It seems that theGOPATH environment variableis 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" )
Copy after login

So try to modify$GOPATHto the same level directory assrc, 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 thegolang tutorialcolumn 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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!