tags:

views:

60

answers:

2

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?

A: 

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.

Scott Wales
-I alone won't work, the package has to be compiled as a package before import can find it
cthom06
+1  A: 

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

cthom06
i'm reading right now and it seems the right page to find answers.in the meantime, i found that the use of gobuild http://code.google.com/p/gobuild/ resolved the problem, at least my simple configuration.
andijcr