douhuan6065
2017-03-05 21:44
浏览 16
已采纳

如何在Go子目录中构建程序?

I have directory structure below. So server.go is in the main dir , and client.go in client sub directory (both are in package main). When I do ' go get -u ...' I have only server.go compiled under the name of MyGoProgram which is fine (executable in $GOPATH/bin)

MyGoProgram
client/client.go
server.go

How do I compile client.go ?

图片转代码服务由CSDN问答提供 功能建议

我在下面有目录结构。 因此,server.go在主目录中,client.go在客户机子目录中(两者都在包main中)。 当我'go get -u ...'时,我只有在MyGoProgram的名称下编译的server.go很好(可以在$ GOPATH / bin中执行)

  MyGoProgram  
client / client.go 
server.go 
   
 
 

如何编译client.go吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutang1946 2017-03-05 22:14
    已采纳

    It's important to match your go directory to the structure described here: https://golang.org/doc/code.html

    so you should have:

    {$GOPATH}/bin
             /pkg
             /src/MyGoProgram/server.go
                             /client/client.go
    

    cd to {$GOPATH} and run the command go install ./src/MyGoProgram the executable will be created at /bin/MyGoProgram.exe

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题