[英]Goland doesn't see functions from another file
I have main.go
file我有
main.go
文件
package main
func main() {
func2()
}
func2
is defined in file2.go
: func2
在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:但是当我通过按
RUN
从Goland
运行它时,它给了我一个错误:
# command-line-arguments
./main.go:95: undefined: func2
How should I overcome it?我应该如何克服它?
Go to Run | Edit Configurations
去
Run | Edit Configurations
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
). Run | Edit Configurations
并将运行配置Type
更改为从File
指向Package
,然后包名称必须是完全限定的(例如github.com/user/package
)。
Edit: You can also right-click on the folder and then select Run | go test <folder name>
编辑:您也可以右键单击该文件夹,然后选择
Run | go test <folder name>
Run | go test <folder name>
. Run | go test <folder name>
。 This will create a run configuration of the type Directory
.这将创建类型为
Directory
的运行配置。
Note: there are differences between the Directory
and Package
type configurations.注意:
Directory
和Package
类型配置之间存在差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.