Opened 15 years ago

Closed 14 years ago

#24661 closed defect (fixed)

go-devel: fatal error: can't find import: fmt on MacPorts

Reported by: tsumekiri@… Owned by: singingwolfboy@…
Priority: Normal Milestone:
Component: ports Version: 1.8.2
Keywords: Cc: paul.richards@…, maccheck@…
Port: go-devel

Description (last modified by jmroot (Joshua Root))

Hi.

I installed Go on MacPorts. But helloworld program can not be comiled.

I installed and compiled as follows:

$ uname -a
Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-
1504.3.12~1/RELEASE_I386 i386

$ sudo port install go-devel

$ cat > hello.go

package main

import "fmt"

func main() {
  fmt.Printf("Hello, 世界\n")
}

$ 6g hello.go
hello.go:3: fatal error: can't find import: fmt

I tried to set GOROOT, didn't know where should I set. I'm sorry if I misunderstood something.

Thank you.

Change History (9)

comment:1 Changed 15 years ago by jmroot (Joshua Root)

Description: modified (diff)
Keywords: golang go removed
Owner: changed from macports-tickets@… to singingwolfboy@…
Port: lang removed

Please remember to preview and use WikiFormatting, and cc the maintainer.

comment:2 Changed 15 years ago by paul.richards@…

Cc: paul.richards@… added

Cc Me!

comment:3 Changed 15 years ago by paul.richards@…

I also get this error.

comment:4 in reply to:  3 ; Changed 15 years ago by singingwolfboy@…

Status: newassigned

It looks like Go compiles its packages and sticks the compiled files in ${worksrcpath}/pkg. I didn't realize this, and I forgot to include that directory in the destroot. Oops.

man porthier doesn't say anything about where to put pkg directories, so I'm not quite sure where it should go. It looks like it belongs in lib, but Go already creates a lib dir separate from pkg, so maybe not. Perhaps include -- but these are compiled files, not C sources. share is out because they're platform-specific.

I'm going to try installing to ${prefix}/pkg on my machine just to see if I can compile Go programs like that. Meanwhile, I'm open to other peoples' suggestions of where to store these files.

comment:5 Changed 15 years ago by singingwolfboy@…

It looks like the deeper problem here is that Go does not allow you to change the GOBIN location once Go has been compiled (as far as I'm aware). As a result, since we compile in ${worksrcpath}/src, Go's tools are going to look for their packages in ${worksrcpath}/pkg rather than looking in ${prefix}.

I figured that the best place to keep Go's packages was lib/gopkg, since Go already has a lib/godoc directory. I implemented this in r67125. So the workaround to compile Go files is to specify the path to these package files with every compilation. For example, with ${prefix} as /opt/local:

6g -I /opt/local/lib/gopkg/ hello.go
6l -L /opt/local/lib/gopkg/ hello.6
./6.out
Hello, 世界

If anyone finds a way to change Go's GOBIN directory after it's been built, let me know!

comment:6 Changed 15 years ago by maccheck@…

Cc: maccheck@… added

Cc Me!

comment:7 in reply to:  6 Changed 15 years ago by frank.maker@…

You can add this workaround to your ~/.bash_profile file as an alias and pretend it isn't even there!

alias 6g='6g -I /opt/local/lib/gopkg/'
alias 6l='6l -L /opt/local/lib/gopkg/'

comment:8 in reply to:  4 Changed 14 years ago by tsumekiri@…

Thank you for your support.

I can now execute "Hello, 世界" by specifying the following way.

6g -I /opt/local/lib/gopkg/ hello.go
6l -L /opt/local/lib/gopkg/ hello.6
./6.out
Hello, 世界

comment:9 Changed 14 years ago by singingwolfboy@…

Resolution: fixed
Status: assignedclosed

Go now allows you to set the GOROOT differently for packaging purposes, so this bug should now be resolved.

Note: See TracTickets for help on using tickets.