【发布时间】:2014-06-18 17:56:30
【问题描述】:
大家好,我是 Golang 的新手,我正在编写一个玩具客户端和服务器应用程序,只是为了学习这些库。
但我有项目文件夹:
philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ echo $GOPATH
/Users/philipherron/workspace/gospace
我想要 2 个二进制文件:
- client.go
- server.go
但是当我构建时,我得到:
philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ go build github.com/redbrain/station/
# github.com/redbrain/station
./server.go:5: main redeclared in this block
previous declaration at ./client.go:5
我想这是因为看起来我正在同一个包中制作电源。
所以我尝试创建一个客户端和一个服务器子目录,并在每个目录中都有二进制文件,但我得到了:
philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ go build github.com/redbrain/station/client
go install github.com/redbrain/station/client: build output "client" already exists and is a directory
我猜这是因为我有以下布局:
$ tree
.
├── client
│ └── client.go
└── server
└── server.go
2 directories, 4 files
不知道如何解决这个问题,在同一个目录中拥有相同的客户端和服务器会很好,但也许这违背了我在 go 中应该做的事情?
【问题讨论】:
-
go build 命令尝试在当前目录中创建一个可执行文件。尝试从不存在名为 client 的文件或目录的目录执行它。
-
谢谢,我没注意到谢谢!