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

huangapple go评论91阅读模式
英文:

How to build program in Go subdirectory?

问题

你可以使用以下命令来编译client.go:

go build ./client

这将在当前目录下的client子目录中编译client.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 ?

答案1

得分: 5

重要的是要将您的go目录与此处描述的结构匹配:https://golang.org/doc/code.html

所以您应该有:

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

切换到{$GOPATH}并运行命令go install ./src/MyGoProgram,可执行文件将被创建在/bin/MyGoProgram.exe中。

英文:

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

huangapple
  • 本文由 发表于 2017年3月6日 05:44:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/42614455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定