cgo error I don't understand

116 views
Skip to first unread message

Robert Solomon

unread,
Nov 3, 2021, 8:39:38 PM11/3/21
to golang-nuts

I'm setting up a new Windows10 computer.  I installed Go 1.17.2 and mingw64 for cgo.  When I tried to compile a project that uses cgo, I got this error:

cgo: exec gcc: gcc resolves to executable relative to current directory (.\\msys64\mingw64\bin\gcc.exe)

This is a program that compiles fine on my older win10 computer.

I don't think this matters, but I'm compiling a program of mine that uses fyne, which uses cgo.

--rob

Ian Lance Taylor

unread,
Nov 4, 2021, 6:20:10 PM11/4/21
to Robert Solomon, golang-nuts
This suggests that the CC environment variable is set to
".\\msys64\mingw64\bin\gcc.exe" with a leading dot. That is not an
absolute path. That is not permitted for the reasons given at
https://golang.org/issue/43783.

Ian

Robert Solomon

unread,
Nov 4, 2021, 7:40:40 PM11/4/21
to golang-nuts
The results of go env are below.  If I'm reading this correctly, CC=gcc.

set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Owner\AppData\Local\go-build
set GOENV=C:\Users\Owner\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Owner\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Owner\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.2
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Owner\go\src\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Owner\AppData\Local\Temp\go-build4162893276=/tmp/go-build -gno-record-gcc-switches

Ian Lance Taylor

unread,
Nov 4, 2021, 7:54:14 PM11/4/21
to Robert Solomon, golang-nuts
Hmmm. What is the path environment variable?

Ian


> On Thursday, November 4, 2021 at 6:20:10 PM UTC-4 Ian Lance Taylor wrote:
>>
>> On Wed, Nov 3, 2021 at 5:40 PM Robert Solomon <drro...@gmail.com> wrote:
>> >
>> > I'm setting up a new Windows10 computer. I installed Go 1.17.2 and mingw64 for cgo. When I tried to compile a project that uses cgo, I got this error:
>> >
>> > cgo: exec gcc: gcc resolves to executable relative to current directory (.\\msys64\mingw64\bin\gcc.exe)
>> >
>> > This is a program that compiles fine on my older win10 computer.
>> >
>> > I don't think this matters, but I'm compiling a program of mine that uses fyne, which uses cgo.
>>
>> This suggests that the CC environment variable is set to
>> ".\\msys64\mingw64\bin\gcc.exe" with a leading dot. That is not an
>> absolute path. That is not permitted for the reasons given at
>> https://golang.org/issue/43783.
>>
>> Ian
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e60e5b03-92d4-4f01-a516-1fca7e2905bdn%40googlegroups.com.

Robert Solomon

unread,
Nov 4, 2021, 8:11:13 PM11/4/21
to golang-nuts
The full error is:
cgo: exec gcc: gcc resolves to executable relative to current directory (.\\msys64\mingw64\bin\gcc.exe)
# github.com/go-gl/gl/v3.2-core/gl

cgo: exec gcc: gcc resolves to executable relative to current directory (.\\msys64\mingw64\bin\gcc.exe)


echo %path is:
C:\Program Files\git\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\gnupg\bin;C:\Program Files\Go\bin;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Owner\AppData\Local\Microsoft\WindowsApps;C:\Users\Owner\go\bin;C:\Users\Owner;C:\Program Files\go\bin;\msys64\mingw64\bin

Roland Müller

unread,
Nov 4, 2021, 11:01:20 PM11/4/21
to Robert Solomon, golang-nuts
Hello,

the entry in the path for mingwin is wrong: it should be either start with C:\ or another drive letter or in case it's an absolute path with double backslash.

Br
Roland
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/306f2cba-ae3b-4e77-94d1-6064f53bba1bn%40googlegroups.com.
>

rob

unread,
Nov 5, 2021, 7:49:52 AM11/5/21
to Roland Müller, golang-nuts

That was it.  It's working now.

Thank you very much.

--rob solomon

Reply all
Reply to author
Forward
0 new messages