douhai9043
douhai9043
2014-01-22 20:12

编译工作正常,但运行失败

已采纳

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • du8864 du8864 7年前

    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.

    点赞 评论 复制链接分享
  • donglun7151 donglun7151 3年前

    You could execute it as:

    go run .
    

    so you don't have to include all files manually.

    点赞 评论 复制链接分享

为你推荐