skip to Main Content

I’ve installed Go 1.13.4 in Debian Linux 10 using brew, package golang (previously I’ve removed golang-1.11 installed via apt). It follows brew info output.

$ brew info golang
go: stable 1.13.4 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/home/linuxbrew/.linuxbrew/Cellar/go/1.13.4 (9,271 files, 408.1MB) *
  Poured from bottle on 2019-12-07 at 14:31:52
From: https://github.com/Homebrew/linuxbrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS is required ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 1,571 (30 days), 8,628 (90 days), 31,650 (365 days)
install-on-request: 784 (30 days), 4,096 (90 days), 13,267 (365 days)
build-error: 0 (30 days)

When I try to execute go build on a package with code calls native OS functions, GO compiler tells that it’s unable to find gcc-5 command as presented below.

$ go build
# _/home/giacomo/src/goproc/process
exec: "gcc-5": executable file not found in $PATH

So I’ve installed latest GCC (9.2.1) from testing (deb http://ftp.us.debian.org/debian testing main contrib non-free) repository and created a symbolic link to /usr/bin/x86_64-linux-gnu-gcc-9.

This solved the problem. But the question is: is this the correct way to fix the problem? Or is there a place to properly configure the GCC used by golang?

Any clarification very appreciated!

5

Answers


  1. (Not really an answer as what you asked is hardly a real question—see below.)

    There’s multiple points which seem wrong with your situation; let’s consider them all.

    The first thing to consider is that “Go” means two things: a language which has certain syntax and semantics, and one of implementations of it.

    Go-the-language has at least two mature implementations: the “reference” one—available from the Go’s main site—and another one—a part of the GCC. Stock contemporary Debian distribution (Debian 10, “Buster”) ships both of them: golang-go is the former and gccgo is the latter.

    As you can see, it’s not clear which one you’ve installed, in the first place.

    The second thing to consider is that the reference implementation (dubbed gc by its original developers for the reasons I forgot) is completely free-standing (and even self-bootstrapping) and does not use any C compiler (from GCC or other) to build Go code. Conversely, gccgo naturally uses other parts of the GCC toolchain to build the Go code.

    Still, Go code features a special subsystem called cgo which can be use to interface Go code with code written in C (and with compiled libraries adhering to the C API. When building a program which uses cgo, both Go suites do rely on at least a C compiler (and may be linker—I don’t know this for sure), and by default gc expects to be able to use a GCC-compatible compiler, and naturally, gccgo uses the C compiler of GCC, too.

    Let’s now recap a bit.

    As you should supposedly see by now, you at least ought to sort several things for you:

    • What implementation of Go you’re talking about (and/or want installed)?
    • Is what you have installed by brew is really what you intended to get?
    • Does the code you’re trying to build use cgo?

    The fourth thing to consider is why on Earth have you decided to use a kludge invented to help Mac users compensate for the lack of package management system on their platform to deal with packages in Debian.

    Debian already ships Go; if you’re not satisfied with the its packaged version (1.11), it looks simpler to merely grab the latest-and-greatest binary package from https://golang.org/dl, unack it and use.

    Another thing to consider is that since version 1.5 Go is self-bootstrapping because it’s written in Go, so if you want to have the latest upstream version, you can just apt install golang-go — to have some version of Go installed — and then use it to build the latest one, like this:

    1. Get the Go source code:

      $ cd ~
      $ mkdir golang
      $ git clone https://github.com/golang/go golang
      
    2. Pick the version you want to build:

      $ cd golang
      $ git checkout go1.13.5
      $ cd src
      $ ./make.bash
      
    3. Then make sure you have /home/user/golang/bin listed in your $PATH.

    Note that building Go is lightning-fast: on a laptop with SSD it builds from cold start in under a minute.

    Login or Signup to reply.
  2. Since it looks like you have installed go with linuxbrew, you can also install gcc-5:

    brew install gcc@5
    

    This solves the problem for me cleanly.

    Login or Signup to reply.
  3. Another option to try is setting the CC environment variable to gcc.

    Login or Signup to reply.
  4. got this issue in linuxbrew. to fix run:

    go env -w CC=gcc CXX="g++"
    

    This uses the system gcc/g++ instead of the ones from linuxbrew

    Login or Signup to reply.
  5. An answer based on nemo’s answer.

    If you have Go installed via the system’s package manager
    and you installed linuxbrew on that system
    and somehow, in my case I installed buf via brew,
    linuxbrew’s go package was pulled in,
    you system’s Go package was replaced by brew’s Go package.

    So in order to use your system’s Go package again you have to uninstall brew’s Go package.

    brew uninstall go

    or if you want to keep brew’s Go package, do what nemo answered:

    go env -w CC=gcc CXX="g++"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search