gpt4 book ai didi

go - 将 gomake/gotest 用于具有外部依赖项的包

转载 作者:IT王子 更新时间:2023-10-29 02:18:24 28 4
gpt4 key购买 nike

我有以下包 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 以指向 Google 代码存储库,如上所示,在 this advice 之后.

问题是:我可以 goinstall 包,它会安装依赖项,但我不能再使用 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 中出现同样的错误。

我想我遗漏了一些非常基本的东西。我应该如何继续将 gomake/gotest 与上面的 Makefile 一起使用?这应该完全有效,还是我应该使用不同的开发工具?

最佳答案

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

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

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

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

类似地,对于使用goinstall 安装cgo 源,您可以在注释指令中指定CFLAGS 和LDFLAGS。例如。

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

关于go - 将 gomake/gotest 用于具有外部依赖项的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7321946/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com