A
A
alexsuhor2021-03-16 18:59:57
go
alexsuhor, 2021-03-16 18:59:57

Golang standard packages not defined?

Installed the programming language according to this instruction. When launching helloworld, it gives an error

./hw.go:4:2: undefined: fmt
.
Editor: VS Code
OS: Ubuntu 20.04

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Romses Panagiotis, 2021-03-16
@alexsuhor

Instructions here: https://golang.org/doc/tutorial/getting-started
$ go mod init example.com/hello This is an important step.
Secondly, it Printlnis written with a capital letter.

W
WinPooh32, 2021-03-17
@WinPooh32

Never install programs manually to the root of the system, as in your instructions. Almost always there are ready-made packages. It's better to install through the docker, climb into the system - an extreme case.
(and I advise you to return everything as it was before the manual installation)
Go is better to install via snap (but vscode is better via deb from the site):

sudo snap install go --channel=1.16/stable --classic

When other versions are needed, VScode can install the desired version into the folder itself and use it:
ctrl+shift+p, type Go: Locate Configured Go Tools (or you can find the button on the panel below).
It happens that the analyzer can crash and restarting gopls helps: ctrl+shift+p, Go: Restart language Server
And make sure that the extension is installed in the editor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question