2010-06-11 80 views
3

我一直在Go周圍玩了幾個星期,到目前爲止這麼好。 現在我正在寫在不同的文件中分裂這樣一個程序:使用導入語句

. 
|-- geometry 
| |-- cone 
| `-- cone.go 
|-- main.go 
|-- Makefile 

問題是我不能在main.go導入cone.go,編譯器沒有找到它。 有人嗎?

回答

2

如果您不介意閱讀,this link對您所問的問題進行了長時間的討論。

下面是一個簡短的答案。

導入在$ GOROOT/pkg(IIRC)中查找軟件包,它不查找本地目錄。你可以做的是使用go包makefile包括(see here)製作一個單獨的makefile文件,然後讓你的主makefile生成包並通過-I來包含新包在./geometry

+0

我正在閱讀,它似乎是正確的頁面來查找答案。 在此期間,我發現使用gobuild http://code.google.com/p/gobuild/解決了問題,至少我的簡單配置。 – andijcr 2010-06-11 13:15:12

0

gc docs:

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你的編譯器選項。

+0

-I alone won' t的工作,包必須被編譯爲一個包,然後才能找到它 – cthom06 2010-06-11 12:18:10