dongxi8993
2011-07-07 16:07
浏览 66

6g:无此类文件或目录-在Snow Leopard上使用`gomake`构建Go软件包

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

图片转代码服务由CSDN问答提供 功能建议

我有两个 .go 文件, numbers.go numbers_test.go ,我想根据创建新的软件包教程(向下滚动以获取有关文件的详细信息。)所有文件都位于同一目录中。

当我在终端中导航到该目录并键入 gomake 我知道了:

  6g -o _go_.6数字。go
make:6g:没有这样的文件或目录
make:**  * [_go_.6]错误1 
   
 
 

此错误表示无法找到 numbers.go 。 如果我手动执行此行(不移动目录):

  6g -o _go_.6数字.go 
   
 
 <  p>它成功创建了 _go_.6 文件。 那么为什么 gomake 找不到文件? 
 
 

这是我正在使用的文件:

Numbers.go 看起来像这样:

 包裹编号
 
func Double(i int)int {
 return i * 2 
} 
 <  / code>  
 
 

numbers_test.go 看起来像这样:

 软件包编号
 
import(\  n“ testing” 
)
 
type doubleTest结构{
 in,out int 
} 
 
var doubleTests = [] doubleTest {
 doubleTest {1,2},
 doubleTest {2,4}  ,
 doubleTest {-5,-10},
} 
 
func TestDouble(t * testing.T){
 _,dt:= range doubleTests {
v:= Double(dt.in)\  n如果v!= dt.out {
 t.Errorf(“ Double(%d)=%d,想要%d。”,dt.in,v,dt.out)
} 
} 
}  
   
 
 

,最后,我的 Makefile 看起来像这样:

  include $(  GOROOT)/src/Make.inc

TARG=数字
GOFILES = \
数字.go 
 
包括$(GOROOT)/src/Make.pkg
   
 <  / DIV>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanchun2349 2011-07-07 18:14
    已采纳

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题