cross-compile with cgo 'permission denied'

167 views
Skip to first unread message

Liam

unread,
Oct 25, 2016, 2:09:18 PM10/25/16
to golang-nuts
I have these commands in a package script:

  GOPATH="${srcdir}" go get -d -u "${_site}/${pkgname}"
  ...
  GOPATH="${srcdir}" GOOS=linux GOARCH=arm \
CC=arm-unknown-linux-gnueabihf-gcc CGO_ENABLED=1 \ go install -v -ldflags='-s -w -extld=$CC' "${_site}/${pkgname}"

Results:

  runtime/cgo
  go install runtime/cgo: open /usr/lib/go/pkg/linux_arm/runtime/cgo.a: permission denied

My cgo.a files have very diff sizes:

  $ ls -l /lib/go/pkg/*/runtime/cgo*
  -rw-r--r-- 1 root root 64874 Sep  8 00:13 /lib/go/pkg/linux_amd64/runtime/cgo.a
  -rw-r--r-- 1 root root 65054 Sep  8 00:18 /lib/go/pkg/linux_amd64_race/runtime/cgo.a
  -rw-r--r-- 1 root root  2642 Oct 25 03:54 /lib/go/pkg/linux_arm/runtime/cgo.a

I have rebuilt for linux_arm:

   GOOS=linux GOARCH=arm go install -v -a std
   GOOS=linux GOARCH=arm go install -v -a cmd


On Arch Linux x86_64 with go1.7.1 linux/amd64

Dave Cheney

unread,
Oct 25, 2016, 2:13:47 PM10/25/16
to golang-nuts
Unless you have built Go from source and/or your user owns the path Go is installed in, this is one of the few cases where go build is recommended over go install. 

Liam

unread,
Oct 25, 2016, 5:23:28 PM10/25/16
to golang-nuts
What I wanted was the magic incantation (documented nowhere) for linux_arm installation:

   GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install -v -a std
   GOOS=linux GOARCH=arm
CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install -v -a cmd

where CC varies for the toolchain installed.

Would the maintainers mind if I filed an issue for this under the docs tag?

Ian Lance Taylor

unread,
Oct 25, 2016, 6:51:17 PM10/25/16
to Liam, golang-nuts
On Tue, Oct 25, 2016 at 2:23 PM, Liam <networ...@gmail.com> wrote:
> What I wanted was the magic incantation (documented nowhere) for linux_arm
> installation:
>
> GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install
> -v -a std
> GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install
> -v -a cmd
>
> where CC varies for the toolchain installed.
>
> Would the maintainers mind if I filed an issue for this under the docs tag?

Even better than an issue would be a change (see
https://golang.org/doc/contribute.html). But an issue is still OK,
but please tell us where it should be documented. That is, where did
you look? Where would you expect to find this?

Ian

Pietro Gagliardi

unread,
Oct 25, 2016, 6:59:24 PM10/25/16
to Liam, golang-nuts
What part of that magic incantation was not documented?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Liam Breck

unread,
Oct 26, 2016, 5:23:44 PM10/26/16
to Ian Lance Taylor, golang-nuts

On Oct 25, 2016 3:49 PM, "Ian Lance Taylor" <ia...@golang.org> wrote:
>
> On Tue, Oct 25, 2016 at 2:23 PM, Liam <networ...@gmail.com> wrote:
> > What I wanted was the magic incantation (documented nowhere) for linux_arm
> > installation:
> >
> >    GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install
> > -v -a std
> >    GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install
> > -v -a cmd
> >
> > where CC varies for the toolchain installed.
> >
> > Would the maintainers mind if I filed an issue for this under the docs tag?
>
> Even better than an issue would be a change (see
> https://golang.org/doc/contribute.html).  But an issue is still OK,
> but please tell us where it should be documented.

Filed issue here
https://github.com/golang/go/issues/17620

Reply all
Reply to author
Forward
0 new messages