尝试使用Go从GitHub构建软件包时出现错误。

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

Error when trying to build package from github with go

问题

我正在尝试从GitHub安装软件包。https://github.com/adnanh/webhook

版本

  1. $ go version
  2. go version go1.17.5 linux/amd64

.profile:

  1. export PATH=$PATH:/usr/local/go/bin

尝试:

  1. $ go build github.com/adnanh/webhook
  2. 没有必需的模块提供了github.com/adnanh/webhook包:在当前目录或任何父目录中找不到go.mod文件;请参阅'go help modules'

设置

  1. $ go env
  2. GO111MODULE=""
  3. GOARCH="amd64"
  4. GOBIN=""
  5. GOCACHE="/root/.cache/go-build"
  6. GOENV="/root/.config/go/env"
  7. GOEXE=""
  8. GOEXPERIMENT=""
  9. GOFLAGS=""
  10. GOHOSTARCH="amd64"
  11. GOHOSTOS="linux"
  12. GOINSECURE=""
  13. GOMODCACHE="/root/go/pkg/mod"
  14. GONOPROXY=""
  15. GONOSUMDB=""
  16. GOOS="linux"
  17. GOPATH="/root/go"
  18. GOPRIVATE=""
  19. GOPROXY="https://proxy.golang.org,direct"
  20. GOROOT="/usr/local/go"
  21. GOSUMDB="sum.golang.org"
  22. GOTMPDIR=""
  23. GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
  24. GOVCS=""
  25. GOVERSION="go1.17.5"
  26. GCCGO="gccgo"
  27. AR="ar"
  28. CC="gcc"
  29. CXX="g++"
  30. CGO_ENABLED="1"
  31. GOMOD="/dev/null"
  32. CGO_CFLAGS="-g -O2"
  33. CGO_CPPFLAGS=""
  34. CGO_CXXFLAGS="-g -O2"
  35. CGO_FFLAGS="-g -O2"
  36. CGO_LDFLAGS="-g -O2"
  37. PKG_CONFIG="pkg-config"
  38. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build586084061=/tmp/go-build -gno-record-gcc-switches"

有什么问题?

而且我在/root/目录下没有带有pkg和bin子文件夹的go文件夹。

英文:

I am trying to install package from github. https://github.com/adnanh/webhook

Version

  1. $ go version
  2. go version go1.17.5 linux/amd64

.profile:

  1. export PATH=$PATH:/usr/local/go/bin

Try:

  1. $ go build github.com/adnanh/webhook
  2. no required module provides package github.com/adnanh/webhook: go.mod file not found
  3. in current directory or any parent directory; see 'go help modules'

Settings

  1. $ go env
  2. GO111MODULE=""
  3. GOARCH="amd64"
  4. GOBIN=""
  5. GOCACHE="/root/.cache/go-build"
  6. GOENV="/root/.config/go/env"
  7. GOEXE=""
  8. GOEXPERIMENT=""
  9. GOFLAGS=""
  10. GOHOSTARCH="amd64"
  11. GOHOSTOS="linux"
  12. GOINSECURE=""
  13. GOMODCACHE="/root/go/pkg/mod"
  14. GONOPROXY=""
  15. GONOSUMDB=""
  16. GOOS="linux"
  17. GOPATH="/root/go"
  18. GOPRIVATE=""
  19. GOPROXY="https://proxy.golang.org,direct"
  20. GOROOT="/usr/local/go"
  21. GOSUMDB="sum.golang.org"
  22. GOTMPDIR=""
  23. GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
  24. GOVCS=""
  25. GOVERSION="go1.17.5"
  26. GCCGO="gccgo"
  27. AR="ar"
  28. CC="gcc"
  29. CXX="g++"
  30. CGO_ENABLED="1"
  31. GOMOD="/dev/null"
  32. CGO_CFLAGS="-g -O2"
  33. CGO_CPPFLAGS=""
  34. CGO_CXXFLAGS="-g -O2"
  35. CGO_FFLAGS="-g -O2"
  36. CGO_LDFLAGS="-g -O2"
  37. PKG_CONFIG="pkg-config"
  38. GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build586084061=/tmp/go-build -gno-record-gcc-switches"

where is a problem?

And I don't have go folder in /root/ with pkg and bin subfolders

答案1

得分: 2

只有go install可以在任何项目之外工作(没有本地的.go.mod文件)。

自Go 1.16以来,如果参数带有版本后缀(如@latest@v1.0.0),go install会在模块感知模式下构建包,忽略当前目录或任何父目录中的go.mod文件。

这对于安装可执行文件而不影响主模块的依赖项非常有用。

go build应该在本地项目中使用,使用其go.mod依赖项列表。它会编译一个包,但不会安装它。

英文:

Only go install can work outside of any project (without a local .go.mod$

> Since Go 1.16, if the arguments have version suffixes (like @latest or @v1.0.0), go install builds packages in module-aware mode, ignoring the go.mod file in the current directory or any parent directory if there is one.
>
> This is useful for installing executables without affecting the dependencies of the main module.

go build is meant to be used within a local project, with its go.mod dependencies list. It compiles, but does not install, a package.

huangapple
  • 本文由 发表于 2021年12月15日 15:27:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/70359821.html
匿名

发表评论

匿名网友

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

确定