Reputation: 61
I have the problem running file main.go in Intellij.
Main.go and Common.go same package main. I run Main.go in Intellij then consle log display message error: ".\Main.go:9: undefined: showMsg". showMsg is a function of Common.go
Upvotes: 3
Views: 560
Reputation: 370
go.mod
file in the root directory of your project with the following contents:
module mypackage
Feel free to change mypackage
to your own package name.
Upvotes: 0
Reputation: 7477
This video should show you how to solve the problem. You basically need to use a Run Configuration of type Go Application and use a Package kind not File kind.
Upvotes: 3
Reputation: 24344
You are executing go run main.go
from IntelliJ, so it doesn't look for showMsg()
in other files.
You should execute go build
instead, so that all of the files in the main
package would be compiled into a single binary.
Upvotes: 0