O Go, não compila "hello world"

You said you wanted to run the code you have already written in eclipse. So only you know where that file is stored. And exactly that’s the place where you need to cd into.

That file is what we need to see.

Also we need to know it’s name, it’s location and the command you use to run it using go run.


I think that’s olamundo

You can not use that package name for a program you want to run. Runnable programs are required to have package main and also a main function. Your package has the wrong name.

Yesterday, I couldn’t answer anymore, because I ran out of replies for the first day in the forum. Is the file name wrong then? The name is causing it not to compile?

The package name. As I said, the first line has to be package main for runnable programs.

And how do I change?

Use your keyboard to change the first line in your sourcefile.

Pretty much like you created that file in the first place, but the first line having a different package name.


It is?

No.

The first line of your source file. The big edit view in the center of your IDE contains currently this:

package olamundo

import "fmt"

func main() {
    fmt.Println("hello world")
}

And now you have to change the very first line into package main which currently says package olamundo.

What is the next step?

go run name_of_the_file.go, from where the file lives in your terminal. I have no clue about how you would do it in eclipse.

It was the name, now compiled.

Thank you for helping me.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.