-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/link: undefined reference to __imp___iob_func on windows with import C / x/sys/windows #57455
Comments
That stack overflow answer suggests a remedy. Did you try it? |
I did try it but it created other problems. Things get flaky using golang.org/x/sys/windows in conjunction with "C". The stack overflow basically further down says that it's a matter of having libraries compiled with older compilers mixing with code compiled with up to date compilers. https://msdn.microsoft.com/en-us/library/bb531344.aspx#BK_CRT So basically stay away from packages which contain static linked code compiled by an older compiler. I just figured you might want this brought to the attention of the dev team to see if there is anything that needs to be looked at. |
Maybe @alexbrainman has ideas. I don't know much about the Windows build. |
This has happened to me on different projects so much as to render go almost unusable for Windows development at least. This project which does not even include "C" gets the same issue, here is the Golang dependency tree for the project. The problem is this is not a toy project and it kind of stinks having to verify each and every new dependency to see if it will render the project uncompilable with this issue. It's friction. It slows development and kind of erodes the value proposition that go enables you to get stuff done faster. I had to comment out every single thing in my application until I was able to chase it down to github.com/mattn/go-sqlite3. Once that dependency was gone I could compile again.
|
Related issue #51007 |
|
Here is a complete command line repo starting from building a new project and creating a minimal main.go file which reproduces the issue.
|
Here is the go.mod file and the main.go file that causes the above error: main.go
go.mod
|
go env
|
As far as how I set things up I followed the directions from go on how to set up go, and I followed the directions from MINGW on how to set that up. I don't want to repeat that process. But if you wish to introspect the current state I would be happy to work with you on that. But in general people should not have to rebuild their entire environment every time they encounter such issues, there needs to be a more frictionless way to troubleshoot setups. |
We're not asking for your environment to be built from scratch, just the inputs for this particular program, using the invocation given above (
|
Ah I misunderstood I built an entirely new project and thought that would be good enough. Turns out that doing what you asked compileFail no longer fails to compile. I can tell you that this switch you have there really needs to bubble up to the top of search results when people encounter issues like this. Hopefully this trouble report will help that happen. Some people are good at following directions without knowing the WHY in the direction but others not so much for those of us in the latter category we really respond better to instructions when we understand the motivations behind them. I think it probably has something to do with the difference between neurotypical and neruoatypical people.
-a---- 12/26/2022 12:12 PM 3836812 compileFail.exe |
recently windows runners in github CI was changed to pre-install mingw 12.2.0 which broke building crc with the following error: ``` GOARCH=amd64 GOOS=windows go build -tags "containers_image_openpgp" -ldflags="-X github.com/crc-org/crc/v2/pkg/crc/version.crcVersion=2.26.0 -X github.com/crc-org/crc/v2/pkg/crc/version.ocpVersion=4.13.9 -X github.com/crc-org/crc/v2/pkg/crc/version.okdVersion=4.13.0-0.okd-2023-06-04-080300 -X github.com/crc-org/crc/v2/pkg/crc/version.podmanVersion=4.4.4 -X github.com/crc-org/crc/v2/pkg/crc/version.microshiftVersion=4.13.9 -X github.com/crc-org/crc/v2/pkg/crc/version.commitSha=46e313 " -o out/windows-amd64/crc.exe ./cmd/crc C:\hostedtoolcache\windows\go\1.19.13\x64\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1 C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000007.o: in function `_cgo_preinit_init': \\_\_\runtime\cgo/gcc_libinit_windows.c:40: undefined reference to `__imp___iob_func' C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000007.o: in function `x_cgo_notify_runtime_init_done': \\_\_\runtime\cgo/gcc_libinit_windows.c:105: undefined reference to `__imp___iob_func' C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000007.o: in function `_cgo_beginthread': \\_\_\runtime\cgo/gcc_libinit_windows.c:149: undefined reference to `__imp___iob_func' C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000008.o: in function `x_cgo_thread_start': \\_\_\runtime\cgo/gcc_util.c:18: undefined reference to `__imp___iob_func' collect2.exe: error: ld returned 1 exit status mingw32-make: *** [Makefile:105: out/windows-amd64/crc.exe] Error 1 Error: Process completed with exit code 1. ``` this should be fixed in golang 1.20 as per the issue: golang/go#57455
recently windows runners in github CI was changed to pre-install mingw 12.2.0 which broke building crc with the following error: ``` GOARCH=amd64 GOOS=windows go build -tags "containers_image_openpgp" -ldflags="-X github.com/crc-org/crc/v2/pkg/crc/version.crcVersion=2.26.0 -X github.com/crc-org/crc/v2/pkg/crc/version.ocpVersion=4.13.9 -X github.com/crc-org/crc/v2/pkg/crc/version.okdVersion=4.13.0-0.okd-2023-06-04-080300 -X github.com/crc-org/crc/v2/pkg/crc/version.podmanVersion=4.4.4 -X github.com/crc-org/crc/v2/pkg/crc/version.microshiftVersion=4.13.9 -X github.com/crc-org/crc/v2/pkg/crc/version.commitSha=46e313 " -o out/windows-amd64/crc.exe ./cmd/crc C:\hostedtoolcache\windows\go\1.19.13\x64\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1 C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000007.o: in function `_cgo_preinit_init': \\_\_\runtime\cgo/gcc_libinit_windows.c:40: undefined reference to `__imp___iob_func' C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000007.o: in function `x_cgo_notify_runtime_init_done': \\_\_\runtime\cgo/gcc_libinit_windows.c:105: undefined reference to `__imp___iob_func' C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000007.o: in function `_cgo_beginthread': \\_\_\runtime\cgo/gcc_libinit_windows.c:149: undefined reference to `__imp___iob_func' C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\RUNNER~1\AppData\Local\Temp\go-link-867149281\000008.o: in function `x_cgo_thread_start': \\_\_\runtime\cgo/gcc_util.c:18: undefined reference to `__imp___iob_func' collect2.exe: error: ld returned 1 exit status mingw32-make: *** [Makefile:105: out/windows-amd64/crc.exe] Error 1 Error: Process completed with exit code 1. ``` this should be fixed in golang 1.20 as per the issue: golang/go#57455
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to compile the program shown at the bottom of this issue using go build.
What did you expect to see?
I expected my program to compile or at least give me an error in my code.
What did you see instead?
C:\Users\steve\source\goWebView> go build
github.com/steowens/goWebview
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
c:/program files/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-14.0.6-mingw-w64ucrt-10.0.0-r2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\steve\AppData\Local\Temp\go-link-2288540720\000005.o: in function
_cgo_preinit_init': \\_\_\runtime\cgo/gcc_libinit_windows.c:40: undefined reference to
__imp___iob_func'c:/program files/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-14.0.6-mingw-w64ucrt-10.0.0-r2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\steve\AppData\Local\Temp\go-link-2288540720\000005.o: in function
x_cgo_notify_runtime_init_done': \\_\_\runtime\cgo/gcc_libinit_windows.c:105: undefined reference to
__imp___iob_func'c:/program files/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-14.0.6-mingw-w64ucrt-10.0.0-r2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\steve\AppData\Local\Temp\go-link-2288540720\000005.o: in function
_cgo_beginthread': \\_\_\runtime\cgo/gcc_libinit_windows.c:149: undefined reference to
__imp___iob_func'c:/program files/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-14.0.6-mingw-w64ucrt-10.0.0-r2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\steve\AppData\Local\Temp\go-link-2288540720\000006.o: in function
x_cgo_thread_start': \\_\_\runtime\cgo/gcc_util.c:18: undefined reference to
__imp___iob_func'collect2.exe: error: ld returned 1 exit status
Attaching source code for program. I simply have no clue what this error is telling me and there doesn't seem to be any answers on the web as to how to get a clue.
Program: main.go
Here is the go.mod file
Apparently commenting out the following line fixes the compilation issues;
import "C"
And I found this: https://stackoverflow.com/questions/30412951/unresolved-external-symbol-imp-fprintf-and-imp-iob-func-sdl2
So apparently something in the go package "golang.org/x/sys/windows" is incompatible with "C"
The text was updated successfully, but these errors were encountered: