英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论