dougaopu7938 2014-06-18 17:56
浏览 104
已采纳

带有2个可执行文件的Go项目

Hi all I am fairly new to Golang, I am writing a toy client and server app just to learn the libraries.

But I have the project folder:

philipherron@Philips-iMac {~/workspace/gospace/src/github.com/redbrain/station} $ echo $GOPATH
/Users/philipherron/workspace/gospace

I wanted to have 2 binaries:

  • client.go
  • server.go

But when I build I get:

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

I guess this is because it looks like I am making to mains in the same package.

So I tried creating a client and a server subdir and have the binaries in each of those, but I get:

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

I guess this is because I have the layout of:

$ tree
.
├── client
│   └── client.go
└── server
    └── server.go

2 directories, 4 files

Not sure how to get around this, it would just be nice to have the same client and server in the same directory but maybe this is against how I should be doing things in go?

  • 写回答

2条回答 默认 最新

  • douchenbiao0916 2014-06-18 18:09
    关注

    just rename your .go files. The compiler is trying to write to 'client' but 'client' is already taken by the directory.

    $ tree
    .
    ├── client
    │   └── main.go
    └── server
        └── main.go
    
    2 directories, 4 files
    

    And/Or create a script that outputs them with a different name go build -o client client/main.go

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码