简体   繁体   English

Goland 看不到另一个文件中的函数

[英]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 : func2file2.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:但是当我通过按RUNGoland运行它时,它给了我一个错误:

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

How should I overcome it?我应该如何克服它?

Go to Run | Edit ConfigurationsRun | 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.注意: DirectoryPackage类型配置之间存在差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM