go build 工作正常,但 go run 失败 [英] go build works fine but go run fails

查看:30
本文介绍了go build 工作正常,但 go run 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个目录下的主包中有几个文件:

I have a few files in the main package under one directory:

main.go配置文件server.go

main.go config.go server.go

当我这样做时:go build"程序构建完美并且运行良好.当我这样做时:去运行 main.go"它失败了.

When I do: "go build" the program builds perfect and runs fine. When I do: "go run main.go" it fails.

输出:

# command-line-arguments
./main.go:7: undefined: Config
./main.go:8: undefined: Server

未定义的符号是结构体,它们是大写的,因此应该导出.

The symbols that are undefined are structs and they are capitalised so should be exported.

我的 Go 版本:go1.1.2 linux/amd64

My Go version: go1.1.2 linux/amd64

推荐答案

这应该可行

go run main.go config.go server.go

Go run 需要一个或多个文件,它符合那些并且仅符合那些解释缺失符号的文件在原帖中.

Go run takes a file or files and it complies those and only those files which explains the missing symbols in the original post.

这篇关于go build 工作正常,但 go run 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆