Problem importing "net/http" package on Mac OS X (MacPorts build)

338 views
Skip to first unread message

Steven E. Harris

unread,
Oct 31, 2012, 4:19:55 PM10/31/12
to golan...@googlegroups.com
I installed the MacPorts "go" port, which is currently at port version
1.0.2¹. Many basic things work correctly, but today I noticed a problem
when loading certain packages such as "net" and "net/http". Here's a
minimal example to motivate the problem:

,----[ File example.go ]
| package main
|
| import "net/http"
|
| func main() {
| http.ListenAndServe(":8080", nil)
| }
`----

When I try to use "go run" or "go build" against any file like this that
imports "net/http", it fails with the following error:

,----
| load cmd/cgo: package cmd/cgo:
| open /opt/local/src/cmd/cgo: no such file or directory
`----

Now, I do have both the cgo source and a compiled binary, but not in the
location mentioned above:

,----[ Where is cgo? ]
| % find /opt/local -name 'cgo'
| /opt/local/pkg/tool/darwin_amd64/cgo
| /opt/local/src/go-1.0.2/misc/cgo
| /opt/local/src/go-1.0.2/src/cmd/cgo
| /opt/local/src/go-1.0.2/src/pkg/runtime/cgo
`----

Here's what "go env" reports:

,----[ go env output ]
| GOROOT="/opt/local"
| GOBIN=""
| GOARCH="amd64"
| GOCHAR="6"
| GOOS="darwin"
| GOEXE=""
| GOHOSTARCH="amd64"
| GOHOSTOS="darwin"
| GOTOOLDIR="/opt/local/pkg/tool/darwin_amd64"
| GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
| CGO_ENABLED="1"
`----

I've searched for this problem with Google today to the point of
exhaustion; the only similar trouble I see reported concerned a build
for Google AppEngine², which I'm not using here.

How can I figure out why go is looking for cgo along the path
"/opt/local/src"? If this is a problem that I should lay at the feet of
the MacPorts maintainer, please let me know.


Footnotes:
¹ https://trac.macports.org/browser/trunk/dports/lang/go/Portfile
² https://groups.google.com/d/msg/golang-nuts/8BJ0fxrWZd4/5O52qINeTfcJ

--
Steven E. Harris

minux

unread,
Oct 31, 2012, 4:33:59 PM10/31/12
to Steven E. Harris, golan...@googlegroups.com
the problem is that macports shuffles our directories, and so violates
assumption made by the go tool.

in short, do not use macport packaged go, if you want to compile from
source, just grab the source from code.google.cpm/p/go. also note that
we also provide binary packages for mac.

the portfile has several problems.
--


Steven E. Harris

unread,
Oct 31, 2012, 4:51:43 PM10/31/12
to golan...@googlegroups.com
minux <minu...@gmail.com> writes:

> the problem is that macports shuffles our directories, and so violates
> assumption made by the go tool.

I see. I found some discussion on the MacPorts issue tracker concerning
trying to maintain user-installed packages across a version number
bump. Perhaps that's one of the reasons for the chosen locations, but I
don't know what's divergent from what you expect.

> in short, do not use macport packaged go, if you want to compile from
> source, just grab the source from code.google.cpm/p/go. also note that
> we also provide binary packages for mac.

Thank you for the push. I just installed the go build for 64-bit x86 and
it works as expected. For anyone else playing along, this build installs
the go-related artifacts in /usr/local/go.

> the portfile has several problems.

If you can explain what's wrong, I can transcribe it into a defect
report to help correct the situation.

--
Steven E. Harris

minux

unread,
Nov 1, 2012, 3:09:38 AM11/1/12
to Steven E. Harris, golan...@googlegroups.com
On Thu, Nov 1, 2012 at 4:51 AM, Steven E. Harris <s...@panix.com> wrote:
minux <minu...@gmail.com> writes:

> the problem is that macports shuffles our directories, and so violates
> assumption made by the go tool.

I see. I found some discussion on the MacPorts issue tracker concerning
trying to maintain user-installed packages across a version number
bump. Perhaps that's one of the reasons for the chosen locations, but I
don't know what's divergent from what you expect.
the go tool expects all internal commands (cgo, 6g, 6l, etc) to be placed at
$GOROOT/pkg/tool/$GOOS_$GOARCH/.

minux

unread,
Nov 1, 2012, 3:22:30 AM11/1/12
to Steven E. Harris, golang-nuts
On Thu, Nov 1, 2012 at 4:51 AM, Steven E. Harris <s...@panix.com> wrote:
> the portfile has several problems.

If you can explain what's wrong, I can transcribe it into a defect
report to help correct the situation.
1. we don't depends on bison, make, gawk or ed any more. to build go, you
will only need a working toolchain and bash (pre-installed on mac).
2. no more gomake
3. i don't think "godoc -http :6060" will work correctly after installation
as doc directory is installed under ${prefix}/share/doc/, not the expected
$GOROOT/doc; also favicon.ico is installed in the wrong place.

there might be other issues.
Reply all
Reply to author
Forward
0 new messages