我一直在Go周围玩了几个星期,到目前为止这么好。 现在我正在写在不同的文件中分裂这样一个程序:使用导入语句
.
|-- geometry
| |-- cone
| `-- cone.go
|-- main.go
|-- Makefile
问题是我不能在main.go导入cone.go,编译器没有找到它。 有人吗?
我一直在Go周围玩了几个星期,到目前为止这么好。 现在我正在写在不同的文件中分裂这样一个程序:使用导入语句
.
|-- geometry
| |-- cone
| `-- cone.go
|-- main.go
|-- Makefile
问题是我不能在main.go导入cone.go,编译器没有找到它。 有人吗?
如果您不介意阅读,this link对您所问的问题进行了长时间的讨论。
下面是一个简短的答案。
导入在$ GOROOT/pkg(IIRC)中查找软件包,它不查找本地目录。你可以做的是使用go包makefile包括(see here)制作一个单独的makefile文件,然后让你的主makefile生成包并通过-I
来包含新包在./geometry
Flags:
-o file
output file, default 6.out for 6g, etc.
-e normally the compiler quits after 10 errors; -e prints all errors
-I dir1 -I dir2
add dir1 and dir2 to the list of paths to check for imported packages
-N disable optimization
-S write assembly language text to standard output
-V print the compiler version
尝试增加-I geometry
你的编译器选项。
-I alone won' t的工作,包必须被编译为一个包,然后才能找到它 – cthom06 2010-06-11 12:18:10
我正在阅读,它似乎是正确的页面来查找答案。 在此期间,我发现使用gobuild http://code.google.com/p/gobuild/解决了问题,至少我的简单配置。 – andijcr 2010-06-11 13:15:12