使用Sublime 3时返回“go run: no go files listed”错误。

huangapple go评论110阅读模式
英文:

Go with Sublime 3 returns "go run: no go files listed"

问题

我在Go教程的第一页上有以下代码:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

我将文件保存在Sublime 3中,文件名为goTour,类型为go。当我构建时,出现以下错误:

go run: no go files listed
[Finished in 0.3s with exit code 1]
[cmd: go run C:\Users\new customer\Desktop\goTour]
[dir: C:\Users\new customer\Desktop]
[path: C:\Windows\System32\;"C:\Program Files\Java\jdk1.7.0_25"\bin;C:\devtools\apache-maven-3.0.5\bin;C:\Program Files\TortoiseHg;C:\Python34;C:\Go\bin]

是否有其他人遇到过这个问题或知道如何解决?我已经安装了Go和gosublime。

英文:

I have the following code from page one in the go tour:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

I saved the file in Sublime 3 with the name goTour and as the type go. When I build, I get:

go run: no go files listed
[Finished in 0.3s with exit code 1]
[cmd: go run C:\Users\new customer\Desktop\goTour]
[dir: C:\Users\new customer\Desktop]
[path: C:\Windows\System32\;"C:\Program Files\Java\jdk1.7.0_25"\bin;C:\devtools\apache-maven-3.0.5\bin;C:\Program Files\TortoiseHg;C:\Python34;C:\Go\bin]

Has anyone else experienced this problem or know how to solve it? I have installed go and gosublime.

答案1

得分: 9

在项目的根目录下的 .go 文件中有一个 main() 函数,这对我来说是有效的:

$ go run .
英文:

With main() function present in .go file within project's root, this works for me:

$ go run .

答案2

得分: 2

将文件保存为tour.go(注意扩展名**.go**)。

Sublime尝试运行的命令是

go run C:\Users\new customer\Desktop\goTour

所以显然它没有正确的扩展名。在Sublime中的类型并不真正重要。

英文:

Save the file as tour.go (mind the extension .go).

The command sublime tries to run is

go run C:\Users\new customer\Desktop\goTour

So it obviously does not have the right extension. The type in sublime does not really matter.

答案3

得分: 2

我的工作环境是Ubuntu 14.04。

我的工作目录结构如下:

$HOME/go/src -> 用于存储tour.go文件

$HOME/go/bin -> 用于存储tour可执行文件

我希望你在终端中的当前工作目录是"src"目录。然后运行以下命令:

$ go run tour.go

如果你想运行/执行编译后的文件,请使用以下命令:

$ $HOME/go/bin/tour

英文:

My Working Environment is Ubuntu 14.04.

My Working Directory Structure.

$HOME/go/src -> for storing tour.go file

$HOME/go/bin -> for storing tour executable file

I am hoping that you are in the present working "src" directory in your terminal.
Then the command will be:

$ go run tour.go

If you want to run/execute compiled file then use this command:

$ $HOME/go/bin/tour

答案4

得分: 1

在GoSublime中,我所做的一切都是在包目录下使用9o提示符(#)并输入:

 run

来运行我的代码... 这是它的样子:

[ ~/Documents/software/go_tests/src/hello/ ] # run
	你好,世界
[ `run` | 完成: 1.767649毫秒 ]
英文:

In GoSublime, all I did was under the package directory with 9o prompt (#) and type:

 run

to run my code... this is what it looks like:

[ ~/Documents/software/go_tests/src/hello/ ] # run
	hello, world
[ `run` | done: 1.767649ms ]

huangapple
  • 本文由 发表于 2014年11月12日 23:51:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/26891076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定