go build工作正常,但运行失败 [英] go build works fine but go run fails
本文介绍了go build工作正常,但运行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在主程序包中的一个目录下有几个文件:
main.go
config.go
server.go
当我这样做:go build程序构建完美,运行良好。
当我这样做:go run main.go它失败。
输出:
#command-line-arguments
./main.go:7:undefined:Config
./main.go:8:undefined:Server
未定义的符号是结构体,它们都是大写的,所以应该导出。
My Go版本:go1.1.2 linux / amd64
解决方案
这应该起作用
go运行main.go config.go server.go
Go运行需要一个或多个文件,它符合那些只有那些解释了原始帖子中缺少的符号的文件。
I have a few files in the main package under one directory:
main.go config.go server.go
When I do: "go build" the program builds perfect and runs fine. When I do: "go run main.go" it fails.
Output:
# 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.
My Go version: go1.1.2 linux/amd64
解决方案
This should work
go run main.go config.go server.go
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工作正常,但运行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文