macos - 无法构建开源项目

标签 macos go build

我想为使用 go 构建的 OSS 项目做出贡献,但我很难编译它。看起来好像我遗漏了一些明显的东西。

我认为问题与 go 在我的计算机上的安装方式有关,而不是与项目本身有关,因此我将其发布在 StackOverflow 上,而不是项目的“问题”部分。

下面是我正在做的。

  1. 我已经安装了 go使用 自制软件:

    $ brew install go
    Updating Homebrew...
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> Updated Formulae
    libebml
    
    ==> Downloading https://homebrew.bintray.com/bottles/go-1.8.3.sierra.bottle.tar.gz
    Already downloaded: /Users/gmile/Library/Caches/Homebrew/go-1.8.3.sierra.bottle.tar.gz
    ==> Pouring go-1.8.3.sierra.bottle.tar.gz
    ==> Caveats
    A valid GOPATH is required to use the `go get` command.
    If $GOPATH is not specified, $HOME/go will be used by default:
      https://golang.org/doc/code.html#GOPATH
    
    You may wish to add the GOROOT-based install location to your PATH:
      export PATH=$PATH:/usr/local/opt/go/libexec/bin
    ==> Summary
    🍺  /usr/local/Cellar/go/1.8.3: 7,035 files, 282.0MB
    $
    
  2. 然后我克隆了存储库:

    $ hub clone lucapette/fakedata
    
  3. 我运行了 make setup(根据指令),起初没有成功完成:

    $ make setup
    go get -u github.com/alecthomas/gometalinter
    gometalinter --install
    make: gometalinter: No such file or directory
    make: *** [setup] Error 1
    $
    

    我认为这是因为 gometalinter 不在我的 $PATH 中,所以添加了它(我正在使用 fish-shell ):

    $ set fish_user_paths /Users/gmile/go/bin
    
  4. 运行 make setup 现在似乎已经成功了。这是输出:

    $ make setup
    go get -u github.com/alecthomas/gometalinter
    gometalinter --install
    Installing:
      aligncheck
      deadcode
      dupl
      errcheck
      gas
      goconst
      gocyclo
      goimports
      golint
      gosimple
      gotype
      ineffassign
      interfacer
      lll
      megacheck
      misspell
      safesql
      staticcheck
      structcheck
      unconvert
      unparam
      unused
      varcheck
    $
    
  5. 运行 make build 失败:

    $ make build
    go build
    main.go:11:2: cannot find package"github.com/lucapette/fakedata/pkg/fakedata" in any of:
            /usr/local/Cellar/go/1.8.3/libexec/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOROOT)
            /Users/gmile/go/src/github.com/lucapette/fakedata/pkg/fakedata (from $GOPATH)
    main.go:12:2: cannot find package "github.com/spf13/pflag" in any of:
            /usr/local/Cellar/go/1.8.3/libexec/src/github.com/spf13/pflag (from $GOROOT)
            /Users/gmile/go/src/github.com/spf13/pflag (from $GOPATH)
    make: *** [build] Error 1
    $
    

所以要么 Contributing指南不完整,或者我遗漏了一些关于安装和管理 go 包的明显信息。

最佳答案

克隆源代码时的路径必须位于 golang PATH 中,例如: /home/gujarat/golang/src/github.com/lucapette/fakedata

如您所见,我的 golang 路径路径是:/home/gujarat/golang/。 您还可以通过输入以下命令在终端中打印您的 golang 路径:$GOPATH

并且 git clone 应该在以下与上面完全相同的路径中:src/github.com/lucapette/

cd $GOPATH/src/github.com/
mkdir lucaptte
cd lucapette
git clone https://github.com/lucapette/fakedata.git

当您运行触发 go buildmake 命令时,此命令将查看 $GOPATH 和您的 $GOROOT 文件夹。

关于macos - 无法构建开源项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45771734/

相关文章:

c# - 使用 System.Runtime.InteropServices 但未找到 HandleRef

android - 实现 SeekArc 时构建同步失败

python - 为什么我不能在 IPython 笔记本中导入 OpenCV (cv2)?

ubuntu - 在 Ubuntu 上设置 GOPATH - 仍然出现错误

xml - 如何更改 struct XML 标签?

arrays - 在Go中,如何解码包含结构数组的字符串

java - 如何在 OS X 中检测屏幕是否关闭?

macos - 在 Mac 上延迟(动态)加载框架(或 dylib)

macos - rust 为什么target/debug/deps 目录那么大

android - 在 Linux 上为 Android 构建 Ionic 应用程序失败,退出代码 2 : Failed to find 'ANDROID_HOME'