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