Goland doesn't see functions from another file

Viewed 1997

I have main.go file

package main

func main() {
    func2()
}

func2 is defined in file2.go:

package main

func func2(){
    ...
}

Everything is OK when I compile and run it from a command line:

go run main.go file2.go

But when I run it from Goland by pressing RUN it gives me an error:

# command-line-arguments
./main.go:95: undefined: func2

How should I overcome it?

1 Answers

Go to Run | Edit Configurations and change the run configuration Type to point from File to a Package, then the package name must be fully qualified (for example github.com/user/package).

Edit: You can also right-click on the folder and then select Run | go test <folder name>. This will create a run configuration of the type Directory.

Note: there are differences between the Directory and Package type configurations.

Related