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

如果我的 Golang 包名称是以下之一,是否可以构建(安装、获取等)名称为 foobar 的可执行文件:

  • github.com/username/go-foobar
  • github.com/username/foobar-tools

并且在包根目录中有 main.go

最佳答案

go build -o <your desired name>

您可以使用带有 go build 的 -o 开关指定可执行文件名称。对于您的示例,它看起来像: cd $GOPATH/github.com/username/go-foobar && go build -o foobar。然而,你只剩下包文件夹中的可执行文件——你仍然需要以某种方式安装它。

但是,我不知道有什么方法可以为使用 go get github.com/username/go-foobar 安装您的工具的人指定。例如,请参阅此答案:https://stackoverflow.com/a/33243591/2415176

如果您不担心人们使用 go get 安装您的工具,那么您可以将这种东西包装在 Makefile 中。

https://stackoverflow.com/questions/42706246/

相关文章:

xcode - 无法将 testflight 与从 XCode 7.0.1 上传的构建一起使用

python - 问题构建 cx_Oracle - libclntsh.so.11.1 => 未找到

build - 即使测试失败,Teamcity 也会运行构建步骤

c++ - 未找到/usr/local/lib 中的库

iphone - 为什么 Xcode 会在钥匙串(keychain)中自动安装(重复和过期的)证书?

visual-studio-2010 - 无法使用 devenv 编译 vdproj - 'targ

python - Matplotlib 构建问题 : Error C1083: Cannot ope

android - 使用没有运行的 Eclipse 重建 .apk

build - 您使用什么工具来构建 Erlang 程序?

build - Xcode 4 术语 "Build for testing/Build for ru