将gomake / gotest用于具有外部依赖性的包

时间:2011-09-06 14:57:23

标签: go packaging

我有以下包Makefile:

include ${GOROOT}/src/Make.inc

TARG=gorilla.googlecode.com/hg/gorilla/mux

GOFILES=\
        doc.go\
        mux.go\

DEPS=\
        gorilla.googlecode.com/hg/gorilla/context

include ${GOROOT}/src/Make.pkg

我今天更改了TARG和DEPS以指向上面显示的G​​oogle代码存储库this advice

问题是:我可以去安装包,它会安装依赖项,但我不能再使用gotest或gomake了;我收到以下错误(使用Go r59):

moraes@yukon:~/dev/repos/gorilla/gorilla/mux$ gotest
rm -f _test/gorilla.googlecode.com/hg/gorilla/mux.a
make -C gorilla.googlecode.com/hg/gorilla/context install
make: *** gorilla.googlecode.com/hg/gorilla/context: No such file or directory.  Stop.
make: *** [gorilla.googlecode.com/hg/gorilla/context.make] Error 2
gotest: "/home/moraes/dev/repos/go/go.r59/bin/gomake testpackage GOTESTFILES=mux_test.go" failed: exit status 2

我尝试首先安装依赖项(goinstall gorilla.googlecode.com/hg/gorilla/context),并在$ GOROOT / pkg中正确安装,但gotest / gomake出现同样的错误。

我想我错过了一些非常基本的东西。我应该如何使用上面的Makefile使用gomake / gotest?这应该是可行的,还是应该使用不同的开发?

2 个答案:

答案 0 :(得分:1)

goinstall根本不使用Makefile。相反,它将直接从您的.go文件解析依赖项。

要指定依赖项,annotate your import lines以及对依赖项的“规范化”引用。例如

import (
  gorilla_context "gorilla.googlecode.com/hg/gorilla/context"
...

gomake不会自动解析依赖关系,因此您必须手动安装它们。

同样,要使用goinstall安装cgo源,您可以在comment指令中指定CFLAGS和LDFLAGS。例如

/*
#cgo CFLAGS: -I/usr/local/include
#cgo LDFLAGS: -L/usr/local/lib -lzmq
#include <zmq.h>
*/
import "C"

答案 1 :(得分:0)

我认为Makefile正在尝试在当前目录中找到文件gorilla.googlecode.com/hg/gorilla/context。另外,为什么要在make文件中指定它而不是从Source中导入它?