FAQ
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

--

Search Discussions

  • Minux at Oct 31, 2012 at 8:34 pm
    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.
    On Thursday, November 1, 2012, Steven E. Harris wrote:

    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

    --

    --
  • Steven E. Harris at Oct 31, 2012 at 11:43 pm

    minux 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 at Nov 1, 2012 at 7:10 am

    On Thu, Nov 1, 2012 at 4:51 AM, Steven E. Harris wrote:

    minux <minux.ma@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 at Nov 1, 2012 at 7:22 am

    On Thu, Nov 1, 2012 at 4:51 AM, Steven E. Harris 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.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 31, '12 at 8:34p
activeNov 1, '12 at 7:22a
posts5
users2
websitegolang.org

2 users in discussion

Minux: 3 posts Steven E. Harris: 2 posts

People

Translate

site design / logo © 2021 Grokbase