Context not compiling with gccgo

The golang.org/x/net/go17.go, which is used by sqlite3 throws an error if I want to compile my project and I have not been able to figure out the problem yet.

# golang.org/x/net/context
../golang.org/x/net/context/go17.go:10:9: error: import file ‘context’ not found
  "context" // standard library's context, as of Go 1.7
         ^
../golang.org/x/net/context/go17.go:16:15: error: reference to undefined name ‘context’
  background = context.Background()
               ^
../golang.org/x/net/context/go17.go:15:15: error: reference to undefined name ‘context’
  todo       = context.TODO()
               ^
../golang.org/x/net/context/go17.go:20:16: error: reference to undefined name ‘context’
 var Canceled = context.Canceled
                ^
../golang.org/x/net/context/go17.go:24:24: error: reference to undefined name ‘context’
 var DeadlineExceeded = context.DeadlineExceeded
                        ^
../golang.org/x/net/context/go17.go:33:12: error: reference to undefined name ‘context’
  ctx, f := context.WithCancel(parent)
            ^
../golang.org/x/net/context/go17.go:47:12: error: reference to undefined name ‘context’
  ctx, f := context.WithDeadline(parent, deadline)
            ^
../golang.org/x/net/context/go17.go:71:9: error: reference to undefined name ‘context’
  return context.WithValue(parent, key, val)
         ^

All files are in the appropriate directory. The wanted file context.go. I didn’t make any changes to it. Context.go is stored in golang.org/x/net/context/.
Here my go environment:
GOARCH=“arm"
GOBIN=”“
GOEXE=”"
GOHOSTARCH=“arm"
GOHOSTOS=“linux"
GOOS=“linux"
GOPATH=”/home/pi/go"
GORACE=”“
GOROOT=”/usr/lib/go-1.7"
GOTOOLDIR=”/usr/lib/go-1.7/pkg/tool/linux_arm"
CC=“gcc"
GOGCCFLAGS=”-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build138640187=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED=“1”

And here my gccgo Version:
gccgo (Raspbian 6.3.0-18+rpi1) 6.3.0 20170516
Copyright © 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Does someone have any clue what could be the problem here?

Hey there!

From the look of the errors your code is throwing I’d say you’re trying to import a library that you haven’t downloaded or placed in your Go PATH. The link you’ve provided are broken so I can’t be sure.

The console says that it cannot find context, which is part of the same library as go17.go

In this case both the error and GOPATH are copied from terminal

You are using a version of gccgo that does not have the “context” package in the standard library, but you are using a go tool that thinks that you are using a release that does provide “context”. You are using GCC version 6.3, which provides a copy of the Go 1.6 library, which does not include “context”. The Go tool appears to think that you have (at least) Go 1.7. I’m guessing that you are not using the go tool that comes with gccgo; that might be the simplest fix here. Or, you could upgrade to GCC 7. Or, you could edit your copy of golang.org/x/net/context to add a !gccgo build tag to context/go17.go, but of course you’ll need to remove it later when you upgrade gccgo. Unfortunately I don’t know of a good way to use the gc version of the go tool and get the correct release tags for a different gccgo version.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.