douzuanze0486 2013-12-02 18:22
浏览 113

从源代码构建项目

How can I build a Go project from source, instead of using go get domain.com/dir/project? For example, instead of

go get github.com/kr/godep

I want to build from the source:

git clone https://github.com/kr/godep.git
cd godep
GOPATH=/tmp/godep go build

The commands above will result in

dep.go:4:2: cannot find package "code.google.com/p/go.tools/go/vcs" in any of:
    /usr/local/Cellar/go/1.2/libexec/src/pkg/code.google.com/p/go.tools/go/vcs (from $GOROOT)
    /Users/hanxue/Source/godep/godep/src/code.google.com/p/go.tools/go/vcs (from $GOPATH)
save.go:5:2: cannot find package "github.com/kr/fs" in any of:
    /usr/local/Cellar/go/1.2/libexec/src/pkg/github.com/kr/fs (from $GOROOT)
    /Users/hanxue/Source/godep/godep/src/github.com/kr/fs (from $GOPATH)

Note: go 1.2 is installed in /usr/local/Cellar/go/1.2 with a link from /usr/local/Cellar/go/1.2/bin/go to /usr/local/bin/go

  • 写回答

1条回答 默认 最新

  • dqp21271 2013-12-03 08:47
    关注

    You need the GOPATH configured correctly. Sometimes a project doesn't have to be checked out in the "sub path" it expects, but often it does and certainly things that depend on it will expect to find it there. So instead of "go get" you can

    mkdir -p /tmp/go/src
    export GOPATH=/tmp/go
    cd $GOPATH/src
    mkdir -p github.com/kr/godep
    cd github.com/kr/godep/..
    git clone http://github.com/kr/godep.git
    cd godep
    go build
    

    ... now rinse and repeat for each dependency!

    cd $GOPATH/src
    mkdir -p code.google.com/p/
    cd code.google.com/p
    hg clone https://code.google.com/p/go.tools/
    

    Yes, the vcs dependency was in "go.tools" and needed to be cloned with hg instead. It took a bit of web browsing to figure out. Okay, I think you can see why that's annoying to do by hand.

    I'll leave the rest of the dependencies as an exercise for the reader, or you can just use "go get". :-)

    A bonus tip that might be what you are really looking for: After checking out the first project, you can use "go get" in that directory to download the dependencies of the project. Sometimes if you have something that's not "go get'able" that's useful if the dependencies are.

    评论

报告相同问题?

悬赏问题

  • ¥15 touchsocket udp组播
  • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
  • ¥15 VS2012中查询语句无法填入解析,数值传不进去
  • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
  • ¥15 怎么让ai定时给我发信息 c#或者python
  • ¥15 scrapy的Error
  • ¥15 RBF-VSG姚凤军论文复现问题
  • ¥30 开发一个APP商城在制作tabbar的时候运行不了代码没有检查出错误,但是显示不出tabbar,以下为运行结果,如何解决?
  • ¥15 多网卡服务器中winform如何绑定指定网卡
  • ¥15 关于#python#pandas#的问题,想要实现:多个TXT导入Excel,进行分列,不同txt之间都从第一行开始,请各位专家解答!