无法构建开源项目

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

Cannot build open-source project

问题

我想为一个使用go构建的开源项目做贡献,但是我在编译它时遇到了困难。看起来我可能漏掉了一些显而易见的东西。

我认为问题与我计算机上安装的go有关,而不是与项目本身有关,所以我在这里发布了这个问题,而不是在项目的“Issues”部分。

以下是我所做的事情。

  1. 我使用homebrew安装了go

    $ brew install go
    更新 Homebrew...
    ==> 自动更新 Homebrew!
    已更新 1 个 tap(homebrew/core)。
    ==> 已更新的 Formulae
    libebml
    
    ==> 正在下载 https://homebrew.bintray.com/bottles/go-1.8.3.sierra.bottle.tar.gz
    已下载:/Users/gmile/Library/Caches/Homebrew/go-1.8.3.sierra.bottle.tar.gz
    ==> 正在倒入 go-1.8.3.sierra.bottle.tar.gz
    ==> 提示
    使用 `go get` 命令需要一个有效的 GOPATH。
    如果未指定 $GOPATH,默认将使用 $HOME/go:
      https://golang.org/doc/code.html#GOPATH
    
    您可能希望将基于 GOROOT 的安装位置添加到 PATH 中:
      export PATH=$PATH:/usr/local/opt/go/libexec/bin
    ==> 总结
    🎆  /usr/local/Cellar/go/1.8.3: 7,035 个文件,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包有一些显而易见的东西不了解。

英文:

I'd like to contribute to an OSS project built with go, but I'm having hard time compiling it. It looks as if I'm missing something obvious.

I think the problem is related to how go is installed on my computer, and not to the project itself, thus I'm posting it here on StackOverflow, instead of project's "Issues" section.

Below is what I'm doing.

  1. I've installed go using homebrew:

     $ 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. Then I cloned the repo:

     $ hub clone lucapette/fakedata
    
  3. I ran make setup (per instruction), which at first did not complete successfully:

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

    I figured that is because gometalinter is nowhere in my $PATH, so have added it (I'm using fish-shell):

     $ set fish_user_paths /Users/gmile/go/bin
    
  4. running make setup seem to have succeeded now. This is the output:

     $ 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. Running make build fails:

     $ 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
     $
    

So either Contributing guideline is incomplete, or I'm missing something obvious about installing and managing go packages.

答案1

得分: 5

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

如你所见,我的golang路径是/home/gujarat/golang/。你也可以在终端中输入$GOPATH来打印你的golang路径。

git clone命令应该在以下路径中执行:src/github.com/lucapette/

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

当你运行make命令触发go build时,该命令会查找$GOPATH$GOROOT文件夹。

英文:

Your path when cloning the source must be on the golang PATH like :
/home/gujarat/golang/src/github.com/lucapette/fakedata

as you can see my Path to golang path is : /home/gujarat/golang/.
You can also print your golang path in your terminal by entering : $GOPATH.

And the git clone should be in the following the exact as above path : src/github.com/lucapette/.

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

When you are running the make command which trigger go build this command will look the $GOPATH and your $GOROOT folder.

答案2

得分: 0

你的Go源代码应该位于你的Go路径(GOPATH)中,这里是/Users/gmile/src。使用"go get"命令获取你想要处理的包,然后应该就可以正常工作了。

英文:

Your go source should in your gopath - here it is Users/gmile/src. Use go get to fetch the pkg you want to work on instead and it should work.

huangapple
  • 本文由 发表于 2017年8月19日 20:49:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/45771734.html
匿名

发表评论

匿名网友

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

确定