[go-nuts] Can't import local package

5,374 views
Skip to first unread message

Floufen

unread,
Jun 15, 2012, 5:36:16 PM6/15/12
to golang-nuts
Hi everyone, i'm very new in golang and i can't import a local
package.
I created 2 files :
main.go
--------------------------------------------------
............. package main
............. import (
...................."foo"
............. )

............. func main() {
....................foo.Test()
............. }
--------------------------------------------------
and foo.go
--------------------------------------------------
............. package foo
.............import (
.........................."fmt"
.............)

.............func Test() {
..........................fmt.Println("Test")
.............}
-------------------------------------------------

when i build main.go (go build main.go) I get :
main.go:3:2: import "foo": cannot find package

I don't know how to fix that. I do search but i can't find anything
that help me.

Thank you in advance. (Sorry for my english)

Floufen

unread,
Jun 15, 2012, 6:15:00 PM6/15/12
to golang-nuts
Sorry i miss one thing :
If I try to compile like that : go build i get :
can't load package: package .: found packages foo (foo.go) and main
(main.go) in /home/riad/src
riad@Temple:~/src$

Mathieu Lonjaret

unread,
Jun 15, 2012, 6:27:53 PM6/15/12
to Floufen, golang-nuts
since you named your package foo, you need to place foo.go in
/home/riad/src/foo/
and you need to set GOPATH to /home/riad in your case.

go help gopath
will tell you more.

Floufen

unread,
Jun 15, 2012, 6:36:05 PM6/15/12
to golang-nuts
Thank you so much :D it works.


On 16 juin, 00:27, Mathieu Lonjaret <mathieu.lonja...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages