Ubuntu: cgo: C compiler "gcc-11" not found: exec: "gcc-11": executable file not found in $PATH - go

I am using Ubuntu 20.04, and I installed Go using Homebrew.
The version of Go is go 1.19.
When I run my application with go run . or go build ., this error comes up:
# github.com/mattn/go-sqlite3
cgo: C compiler "gcc-11" not found: exec: "gcc-11": executable file not found in $PATH
I have tried running
sudo apt install gcc
but the terminal tells me that gcc is already the newest version (4:9.3.0-1ubuntu2).
When I run gcc -v
the terminal tells me gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
And I have already run apt update and apt upgrade already, and then reinstall gcc, but it's still version 9.4.0
My question is how do I install gcc-11? Or is it not supported in Ubuntu 20.04? Or should I not use go 1.19?
Thanks

The go developers provide a simple way to manage multiple go versions at once: https://go.dev/doc/manage-install
It should not be too hard to explore if this is a Homebrew artifact, or something generic to go, or a specific version of go on your system.
You might also look at the output of go env which should list configured defaults for various dependencies. You are looking for something like CC=gcc in the output.

Related

How to compile a Go application using gopacket for 32bit mips

I am trying to compile a little application using the gopacket library to linux on a 32bit mips cpu. Unfortunately I am getting loads of errors like this:
/home/cdutz/go/pkg/mod/github.com/google/gopacket#v1.1.19/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
On a "normal" linux system these seem to be defined in "pcap_unix.go" while on windows the values are coming from "defs_windows_amd64.go". I do have the libpcap in a 32bit mips version on my target system, which is good as my target system doesn't have the extra space to install all the tools needed to compile anything on it. I know that libpcap doesn't exist as a 1-to-1 version on windows, so this probably explains the "defs"-files. But I would generally expect it to have the same API as the one on my linux system.
[UPDATE]
So it seems number 1 of the things that needs to be ensured is that cgo is executed. This is done by setting the environment variable:
CGO_ENABLED=1
Next we need to ensure the mips compatible versions of the libpcap are installed (the header files are identical on any architecture). In order to do this on my Ubuntu 16.4 I first needed to enable the 'mips' archirecture:
dpkg --add-architecture mips
And add the debian repo to the /etc/apt/sources.list
deb [trusted=yes] http://ftp.de.debian.org/debian buster main
As soon as that's done, I could install the mips binaries:
apt install libpcap-dev:mips libpcap0.8-dev:mips libc6-dev:mips libdbus-1-dev:mips libpcap0.8:mips
In order to cross compile, it seems I need a gccgo version that can do that. For this I installed:
apt-get install gccgo-mips-linux-gnu
Now comes something I am not sure I did right, but when running the go build with compiler=gccgo it always picked the amd64 version and using anything else but 'gccgo' as compiler argument didn't work, so I updated the symlink in /usr/bin/gccgo to point to: 'mips-linux-gnu-gccgo-8' (in the same directory).
After all of these changes, I was able to almost build everything with this command:
go build -compiler=gccgo
If I enable the additional output with the '-x' option, I can see that cgo is now doing it's thing. It's also compiling all the other modules. But on the pcap one it now fails with:
cc1: error: command line option '-c' is valid for the driver but not for C
So this is where I'm currently stuck at.
Ok, after 3 days I think I managed to get things working and I'll summ up what I did.
In the end the gccgo path was a dead end, so instead of installing gccgo-mips-linux-gnu I installed gcc-mips-linux-gnu.
Next I set the CC environment variable to point to this:
export CC=/usr/bin/mips-linux-gnu-gcc-8
That was actually what was missing.
So summing it up on my Ubuntu 16.04 system:
dpkg --add-architecture mips
echo "deb [trusted=yes] http://ftp.de.debian.org/debian buster main" > /etc/apt/sources.list
apt update
apt install -y wget git build-essential mc
apt install -y gcc-mips-linux-gnu
apt install -y libpcap-dev:mips libpcap0.8-dev:mips libc6-dev:mips libdbus-1-dev:mips libpcap0.8:mips
export CC=/usr/bin/mips-linux-gnu-gcc-8
export GOOS=linux
export GOARCH=mips
export GOMIPS=softfloat
export CGO_ENABLED=1
go build
I hope this might help others.

Install snap on Ubuntu Precise

After a purchase of ARK-20-S8A11E, i find out that it only supports ubuntu 12.04 and that network manager uses snap which only availale on ubuntu 14 onward. I need Mobilemanager to collect information of an LTE module integrated in the PC.
For that, i tried to install snap from source.
I needed "go", and with apt-get install golang, the last version installed on precise is go1. and snap uses go1.6 onward version.
Therefore, i installed the latest version of go from sources. It is well installed, the output of go --version is : go version go1.11.4 linux/amd, and tested a basid hello.go.
I followed this link for snap installation: https://github.com/snapcore/snapd/blob/master/HACKING.mdsnap.
The build command " sudo -E go build -o /tmp/snap github.com/snapcore/snapd/cmd/snap" give an output as the "go command not found".
The GOPATH and PATH are well verified, the go env also.
Could you please help me sort this issue?
Thank you,
sudo is the troublemaker here. When sudoing the $PATH env var is replaced with the secure_path from /etc/sudoers (see this and this.)
Either do not run go as sudo, add the go path to the secure_path or include the full path to go in your command (sudo -E /usr/local/bin/go build -o /tmp/snap github.com/snapcore/snapd/cmd/snap)

exec: "gcc": executable file not found in %PATH% when trying go build

I am using Windows 10. When I tried to build Chaincode it reported this error
# github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11
exec: "gcc": executable file not found in %PATH%
My chaincode imports:
import (
"fmt"
"strconv"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
It's running fine in Docker.
gcc (the GNU Compiler Collection) provides a C compiler. On Windows, install TDM-GCC. The github.com/miekg/pkcs11 package uses cgo. Cgo enables the creation of Go packages that call C code.
If you are running Ubuntu do:
apt-get install build-essential
This solved the problem. It installs the gcc/g++ compilers and libraries.
I also encountered this message, but in my case, it was missing gcc.exe. I used choco and installed mingw, and then it worked.
details:
download choco
choco install mingw -y
check: gcc -v
1) Install .exe from > https://sourceforge.net/projects/mingw-w64/
1.2) ! use x86_64 architecture
2) Add C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin to PATH in User Variables and in System Variables. For me it works.
! To edit Path variable press Windows key, type 'path', choose 'Edit the system environment variables', click 'Environment Variables', find Path variable in System variables and in User variables then edit.
On Windows install http://tdm-gcc.tdragon.net/download, that is all.
If you are using an alpine based image with your Dockerfile
Install build-base which will be met with your requirements.
apk add build-base
$ go env
check CGO_ENABLED if its 1 change it to 0 by
$export CGO_ENABLED=0
For my case :
os: windows 10
command:
choco install mingw
install choco if not installed:
Link: https://www.liquidweb.com/kb/how-to-install-chocolatey-on-windows/
worked for me.
The proper explanations why go build does not work for hyperledger in Windows environment are given as other answers.
For your compilation purposes, just to make it work without installing anything extra, you can try the following
go build --tags nopkcs11
It worked for me. I hope same works for you too.
You can try - this is not a solution but a temp workaround
cgo_enabled=0 go build
Once you install gcc - and make sure %PATH has a way to find it (gcc.exe) - this should go away.
Also running this one will ensure the cgo_enabled variable will stay this way as long as terminal is open. That way you don't have to prefix it each time you do a build.
export cgo_enabled=0 go build
just followed instructions from following and it solve my issue
https://code.visualstudio.com/docs/cpp/config-mingw
it ask to install Mingw-w64 via MSYS2
important command is pacman -S --needed base-devel mingw-w64-x86_64-toolchain
then add C:\msys64\mingw64\bin to PATH
thanks
For Ubuntu, what worked for me was to simply run:
sudo apt install gcc
On Amazon Linux 2:
Install go
wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
Install gcc
sudo yum groupinstall "Development Tools"
I recommend using the package group, even though it can be done without it, because groupinstall gives you the necessary packages to compile software on Amazon Linux and Redhat, CentOS for that matter.
on Ubuntu its very easy but on windows need to do it:
download MinGW on http://www.mingw.org/
install on basic package Gcc-g++ (see this image)
add on environment Patch of windows variables.
restart and continue with "go get ..."
If you are running Ubuntu do:
sudo apt-get update
sudo apt-get install build-essential.
If the above commands do not work do:
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe"
The main component contains applications that are free software, can be freely redistributed and are fully supported by the Ubuntu team. & The universe component is a snapshot of the free, open-source, and Linux world.
Then install package by following command in terminal:
sudo apt-get update
sudo apt-get install build-essential.
For more info click here: https://itectec.com/ubuntu/ubuntu-problem-installing-build-essential-on-14-04-1-lts-duplicate/
Just add this to your Dockerfile
RUN apk add alpine-sdk
gcc should not be necessary, unless you are cross compiling for a non-windows platform, or use cgo.
If you still need gcc, however, you should install MinGW, which provides a gcc port for Windows (Cygwin and msys should also work, although I have never actually tested this).
Edit: I see from your error message now, that it is a dependency that requires gcc. If you didn't already know this, gcc is a c/c++ compiler, and in this case it is probably needed to compile c source files included by a dependency or sub-dependency.
Instruction to fix the "exec: “gcc”: executable file not found in %PATH%" error with MSYS2:
Download MSYS2.
Put MSYS2 folder into your $PATH.
Start the MSYS2 command line program.
Run this command: pacman -S gcc.
Kindly install the MINGW after GUI will automatically take.
http://mingw.org/wiki/Getting_Started
On Windows, you can install gcc by Scoop:
scoop install gcc
you need to download MingGW64
put MingGW64 folder into your $PATH
run go build xxx.go (with cgo library)
Hi jaswanth the main problem is that you haven't register your %GO_HOME%\pkg\tool\windows_amd64 to yuour Environment Path.
%GO_HOME% is the repository where you install your go at the first time.
same as other, just install tdm-gcc, but you can use its terminal, "MinGW", you can access it from start menu folder tdm-gcc, after start, browse to your project, and run it again
I'm a Windows user and I downloaded tdm-gcc (MinGW-w64 based) from the link below:
https://jmeubank.github.io/tdm-gcc/
After installation, it made a folder named "TDM-GCC-64".
I added "C:\TDM-GCC-64\bin" to my PATH, And it fixed my problem.

cygwin bash not returning a valid result

I am following this :
Step 2: Installing Cygwin
Cygwin can be downloaded from http://www.cygwin.com
Run the setup file.
Install from internet. Specify C:\cygwin as the root directory.
In the Select Packages dialog box, select the packages required. gcc-core, gcc-g++, gdb, and make packages are most important. These are the C core, C++ core, the GNU Debugger and the GNU version of ‘make’ utility. These packages will be under the ‘Devel’ category.
Complete the installation.
Step 3: Testing Cygwin
To test whether Cygwin was installed properly, try the following by opening the bash shell:
cygcheck -c cygwin
gcc --version
g++ --version
make --version
gdb --version
If the version details are displayed for all these commands, the installation of Cygwin has been successful.
I got this from here
But the result I get is:
What is wrong or missing with my installation.
Follow up question:
I wanted to use the terminal window in netbeans that is why I installed this.
In this terminal widnow I also have problem. I cant type anything on it. Is this the reason for it?
Try to run /usr/bin/g++. If it is not found, then you don't have g++ installed (installation may have had problems).
You can follow the same procedure for the rest of your commands
If /usr/bin/g++ runs successfully, it means you don't have /usr/bin in your PATH (which is very unlikely). You can put that in your PATH in your startup file.

How to use the gcc compiler in the mac terminal instead of clang

Is there a way to change the compiler to gcc from clang? I have the command line tools installed and am trying to use the terminal to compile instead of xcode itself.
For MacPorts use:
port select --set gcc <group>, <version>
. . as detailed in this answer.
For Homebrew use:
Brew link and brew unlink the package versions that you prefer to use. Note that an "unlinked" package is still installed and usable from /usr/local/opt//, it's just not in the default path.
You can install gcc using any ports system (e.g., MacPorts, http://www.macports.org/)

Resources