英文:
6g: No such file or directory - Building Go packages with `gomake` on Snow Leopard
问题
我有两个.go
文件,numbers.go
和numbers_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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论