开发者

use of import statement

I've been toying around Go for a couple of weeks now,开发者_开发技巧 so far so good. Now I am writing a program splitted across different files like this:

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

the problem is i can't import cone.go in the main.go, the compiler doesn't find it. Anybody?


If you don't mind a bit of reading, this link has a lengthy discussion on the problem you're asking about.

Here's a short answer.

Import looks for package in $GOROOT/pkg (IIRC), it does not look in local directories. What you can do is make a seperate makefile for "geometry" using the go package makefile includes (see here) and then have your main makefile make the package and pass the -I to include the new package in ./geometry


From the 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

Try adding -I geometry to your compiler options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜