回答

收藏

如何使用 Golang 包以外的名称构建可执行文件

技术问答 技术问答 696 人阅读 | 0 人回复 | 2023-09-12

foobar如果我的 Golang 包名称是否可用于构建(安装、获取等)的可执行文件
- G5 s' b2 ?5 x3 \( }  h: pgithub.com/username/go-foobar
1 T" }, u% w! ?0 Kgithub.com/username/foobar-tools
并main.go在包根目录中?
: \! ]4 }& D* f* L) h                                                               
* O. v& ?1 g  e- `7 E2 N5 k4 g    解决方案:                                                               
+ i+ e4 A% P& C: g# ~                                                               
    go build -o
      T$ s6 z! D4 m2 I; g
可以用 -o 开关和go build. 为了你,它看起来像: cd $GOPATH/github.com/username/go-foobar && go build -o foobar。但是,您只剩下包文件夹中的可执行文件——您仍然需要以某种方式安装它。
6 ]# f8 e1 v3 y: o( H; B# |5 Q但是,我不知道么办go get github.com/username/go-foobar指定安装工具的人。$ k9 w* A! J$ n  U
如果你不担心人们使用 安装你的工具go get,然后你可以把这个内容包装在 Makefile 中。
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则