6g:没有这个文件或目录 – 在Snow Leopard上使用`gomake`构建Go包

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

6g: No such file or directory - Building Go packages with `gomake` on Snow Leopard

问题

我有两个.go文件,numbers.gonumbers_test.go,我想按照创建新包教程中的说明构建和执行测试。所有文件都在同一个目录中。

当我在终端中导航到该目录并输入gomake时,我得到以下结果:

6g  -o _go_.6 numbers.go
make: 6g: 没有那个文件或目录
make: *** [_go_.6] 错误 1

这个错误表示它找不到numbers.go文件。如果我手动执行这行命令(不移动目录):

6g  -o _go_.6 numbers.go

它成功创建了_go_.6文件。那么为什么gomake找不到这个文件呢?

以下是我使用的文件:

numbers.go的内容如下:

package numbers

func Double(i int) int {
  return i * 2
}

numbers_test.go的内容如下:

package numbers

import (
	"testing"
)

type doubleTest struct {
	in, out int
}

var doubleTests = []doubleTest{
	doubleTest{1, 2},
	doubleTest{2, 4},
	doubleTest{-5, -10},
}

func TestDouble(t *testing.T) {
	for _, dt := range doubleTests {
		v := Double(dt.in)
		if v != dt.out {
			t.Errorf("Double(%d) = %d, want %d.", dt.in, v, dt.out)
		}
	}
}

最后,我的Makefile的内容如下:

include $(GOROOT)/src/Make.inc

TARG=numbers
GOFILES=\
	numbers.go

include $(GOROOT)/src/Make.pkg
英文:

I have two .go files, numbers.go and numbers_test.go and I want to build and execute the tests as per the creating a new package tutorial (scroll down for details on the files.) All files are in the same directory.

When I navigate to that directory in Terminal and type gomake I get this:

6g  -o _go_.6 numbers.go
make: 6g: No such file or directory
make: *** [_go_.6] Error 1

This error is saying that it cannot find numbers.go. If I manually execute this line (without moving directory):

6g  -o _go_.6 numbers.go

it successfully creates the _go_.6 file. So why can't gomake find the file?

Here are the files I am using:

numbers.go looks like this:

package numbers

func Double(i int) int {
  return i * 2
}

numbers_test.go looks like this:

package numbers

import (
	"testing"
)

type doubleTest struct {
	in, out int
}

var doubleTests = []doubleTest{
	doubleTest{1, 2},
	doubleTest{2, 4},
	doubleTest{-5, -10},
}

func TestDouble(t *testing.T) {
	for _, dt := range doubleTests {
		v := Double(dt.in)
		if v != dt.out {
			t.Errorf("Double(%d) = %d, want %d.", dt.in, v, dt.out)
		}
	}
}

and finally, my Makefile looks like this:

include $(GOROOT)/src/Make.inc

TARG=numbers
GOFILES=\
	numbers.go

include $(GOROOT)/src/Make.pkg

答案1

得分: 2

错误并没有说找不到numbers.go - 它说找不到6g。在你的Makefile中,尝试将6g的路径放入你的PATH中,以及任何其他Go特定的环境变量。

英文:

The error doesn't say that it can't find numbers.go - it's saying that it can't find 6g. In your Makefile, try putting the path to 6g in your PATH, as well as any other Go-specific environment variables.

huangapple
  • 本文由 发表于 2011年7月8日 00:07:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/6613637.html
匿名

发表评论

匿名网友

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

确定