go: cmd/link: cgo linking fails on Windows with GCC 11.2.0 + MinGW-w64 9.0.0 (UCRT) from winlibs.com
Original post: https://github.com/mattn/go-sqlite3/issues/1012
What version of Go are you using (go version
)?
$ go version go version go1.17.5 windows/amd64
Does this issue reproduce with the latest release?
maybe
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env set GO111MODULE= set GOARCH=amd64 set GOBIN=C:\Users\user\Desktop set GOCACHE=C:\Users\user\AppData\Local\go-build set GOENV=C:\Users\user\AppData\Roaming\go\env set GOEXE=.exe set GOEXPERIMENT= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\user\go\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=C:\Users\user\go set GOPRIVATE= set GOPROXY=https://goproxy.io,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.5 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=NUL 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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\user\AppData\Local\Temp\go-build2697353945=/tmp/go-build -gno-record-gcc-switches
What did you do?
import it
and go build
or go run .
What did you expect to see?
no output
What did you see instead?
> go run .
#
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\go-link-2621619269\000016.o: in function `_cgo_preinit_init':
c:\go\src\runtime\cgo/gcc_libinit_windows.c:30: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\go-link-2621619269\000016.o: in function `x_cgo_sys_thread_create':
c:\go\src\runtime\cgo/gcc_libinit_windows.c:60: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\go-link-2621619269\000016.o: in function `x_cgo_notify_runtime_init_done':
c:\go\src\runtime\cgo/gcc_libinit_windows.c:101: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\go-link-2621619269\000017.o: in function `x_cgo_thread_start':
c:\go\src\runtime\cgo/gcc_util.c:18: undefined reference to `__imp___iob_func'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\go-link-2621619269\000018.o: in function `_cgo_sys_thread_start':
c:\go\src\runtime\cgo/gcc_windows_amd64.c:31: undefined reference to `__imp___iob_func'
collect2.exe: error: ld returned 1 exit status
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 26 (14 by maintainers)
Commits related to this issue
- Windows: downgrade MinGW version to work around CGO issue see https://github.com/golang/go/issues/51007 see https://github.com/docker/containerd-packaging/pull/293#issuecomment-1289529251 Signed-off... — committed to thaJeztah/containerd-packaging by thaJeztah 2 years ago
- fix: upgrading go to support windows (#6001) ### Description Due to the latest `windows-2022` runner image no longer including a "built from source" Go binary, we're running into https://github.... — committed to vercel/turbo by chris-olszewski 9 months ago
- Update Go to v1.21.1 in CI & Docker This might also fix the CLI build for Windows: https://github.com/golang/go/issues/51007 — committed to scrtlabs/SecretNetwork by assafmo 9 months ago
- 1.20_windows/runtime/cgo, 1.21_windows/runtime/cgo: remove unnecessary changes Apparently issues with stdio was fixed in Go 1.20. See golang/go#51007 — committed to hajimehoshi/hitsumabushi by hajimehoshi 9 months ago
- 1.20_windows/runtime/cgo, 1.21_windows/runtime/cgo: remove unnecessary changes Apparently issues with stdio was fixed in Go 1.20. See golang/go#51007 — committed to hajimehoshi/hitsumabushi by hajimehoshi 9 months ago
- 1.20_windows/runtime/cgo, 1.21_windows/runtime/cgo: remove unnecessary changes Apparently issues with stdio was fixed in Go 1.20. See golang/go#51007 — committed to hajimehoshi/hitsumabushi by hajimehoshi 9 months ago
- 1.20_windows/runtime/cgo, 1.21_windows/runtime/cgo: remove unnecessary changes Apparently issues with stdio was fixed in Go 1.20. See golang/go#51007 — committed to hajimehoshi/hitsumabushi by hajimehoshi 9 months ago
- .github: build Windows on 1.19 This commit updates the Windows CI job to use Go 1.19 instead of Go 1.18. See golang/go#51007. — committed to jbowens/pebble by jbowens 8 months ago
- .github: build Windows on 1.19 This commit updates the Windows CI job to use Go 1.20 instead of Go 1.18. See golang/go#51007. — committed to jbowens/pebble by jbowens 8 months ago
as a hot fix to keep working in the meantime this worked:
No idea, but I would really like it to be fixed before Go 1.19 because I want to be able to test
cgo
build reproducibility on Windows. 😅That is tracked in #20982. It is currently milestoned
Unplanned
, so I would not expect it to happen unless a contributor outside the Go project steps up to implement it.Hello @thanm and all.
I can confirm that I have the same issue as the OP with 1.19.4 and @Klaus-Tockloth,
and resolved with
go1.20rc1
This is my example file https://github.com/YOU54F/hello_ffi/blob/main/go/helloFfi.go
I am just going through my examples and getting them working on windows.
note, my system deps were
This page was useful for me in working out how to install the release candidate
I have a CL that should (in theory) take care of this problem, https://go-review.googlesource.com/c/go/+/382837. When I get that stack checked in (other parts still need work) I’ll be sure to test this scenario (winlib + gosqlite). Thanks.