Following is my system configuration.
OS : Microsoft Windows 10 Enterprise
Go version: go version go1.15.7 windows/amd64
The program which I am trying to execute is as below
package main
import "fmt"
func main() {
fmt.Println("Hello World from Go")
}
The problem is I can compile and run a simple Hello world program from the command line but inside vscode it showed the error.
could not import fmt (cannot find package "fmt" in any of c:\go\src\fmt (from $GOROOT)
C:\Users\ameena\go\src\fmt (from $GOPATH))compiler
Am I missing here something ??
Regards Amit
CodePudding user response:
As explained here (for GoLand, but it applies to VSCode-Go as well)
GOROOTis a variable that defines where your Go SDK is located.
You do not need to change this variable, unless you plan to use different Go versions.
GOPATHis a variable that defines the root of your workspace.
By default, the workspace directory is a directory that is namedgowithin your user home directory (~/gofor Linux and MacOS,%USERPROFILE%/gofor Windows).
If you did not install Go in the default paths (C:\Go), you need to set the GOROOT environment variable to the root folder of your Go installation.
The OP Amit Meena confirms in the comments:
Seems in my env
GOROOTvariable was missing: on creating theGOROOTvariable and pointing it to go installation directory, the error has gone from VSCode.
