Windows10, undefined reference to `__imp___iob_func'

1,963 views
Skip to first unread message

David Walther

unread,
Sep 7, 2015, 6:54:39 PM9/7/15
to golang-nuts
What is the right way to set up a build environment for Windows?

I have Windows 10, 64 bit. I've installed 32bit and 64bit versions of cygwin.
I've installed msys2 with the mingw-w64 packages. I have Visual Studio 2015
installed.
C:\msys64
C:\cygwin
C:\cygwin64

I run make inside the msys2 terminal program instead of the cygwin command
window.

===== cut here
package main

// #cgo LDFLAGS: -L/mingw64/x86_64-w64-mingw32/lib
// #cgo LDFLAGS: -lws2_32 -liphlpapi
// #define __USE_W32_SOCKETS
// #ifndef _WIN32_WINNT
// #define _WIN32_WINNT 0x0600
// #endif
// #include <stdio.h>
// #include <winsock2.h>
// #include <iphlpapi.h>
// #include <ws2tcpip.h>
// #include <stdlib.h>
import "C"
import "fmt"

func main() {
fmt.Println("Hello WinSock2")
}
===== end cut

Result:

$ make
go fmt foo.go
go build foo.go
# command-line-arguments
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:\msys64\tmp\go-link-142956851/000001.o: In function `x_cgo_sys_thread_create':
C:/workdir/go/src/runtime/cgo/gcc_libinit_windows.c:10: undefined reference to `__imp___iob_func'
C:/workdir/go/src/runtime/cgo/gcc_libinit_windows.c:10:(.text+0x6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp___iob_func'
C:\msys64\tmp\go-link-142956851/000001.o: In function `x_cgo_thread_start':
C:/workdir/go/src/runtime/cgo/gcc_util.c:41: undefined reference to `__imp___iob_func'
C:/workdir/go/src/runtime/cgo/gcc_util.c:41:(.text+0xdc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp___iob_func'
C:\msys64\tmp\go-link-142956851/000001.o: In function `_cgo_sys_thread_start':
C:/workdir/go/src/runtime/cgo/gcc_windows_amd64.c:32: undefined reference to `__imp__beginthread'
C:/workdir/go/src/runtime/cgo/gcc_windows_amd64.c:32:(.text+0x1b3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp__beginthread'
C:/workdir/go/src/runtime/cgo/gcc_windows_amd64.c:34: undefined reference to `__imp__errno'
C:/workdir/go/src/runtime/cgo/gcc_windows_amd64.c:34:(.text+0x1c5): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp__errno'
C:/workdir/go/src/runtime/cgo/gcc_windows_amd64.c:34: undefined reference to `__imp___iob_func'
C:/workdir/go/src/runtime/cgo/gcc_windows_amd64.c:34:(.text+0x1cd): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp___iob_func'
collect2: error: ld returned 1 exit status

Makefile:2: recipe for target 'default' failed
make: *** [default] Error 2

Konstantin Khomoutov

unread,
Sep 8, 2015, 7:06:08 AM9/8/15
to David Walther, golang-nuts
On Mon, 7 Sep 2015 15:54:18 -0700
David Walther <da...@clearbrookdistillery.com> wrote:

> What is the right way to set up a build environment for Windows?

Go 1.5 is written in Go, and you have Go 1.4 installed to compile it.
See [1] for the instructions.

> I have Windows 10, 64 bit. I've installed 32bit and 64bit versions
> of cygwin. I've installed msys2 with the mingw-w64 packages. I have
> Visual Studio 2015 installed.

This is way too much. You only ever need Cygwin if you want to run a
program which is compiled *for* Cygwin or is a part of it.
Go build toolchain never used Cygwin IUUC, and I've never heard of Go
being built for the Cygwin runtime.

MinGW could indeed been used to build Go < 1.5, and that was the
blessed (or the sole?) way to do it.

As to Visual Studio, I have no idea. AFAIK, the `cgo` subsystem of Go
(the support in the `go` tool and the compiler for helping Go code
interoperate with code written in C) has always depended on MinGW on
Windows.

[...]

In either case, since Go 1.5 onwards Go is written in Go and to build
it, you just have a working (prior) Go installation, which is currently
1.4.

1. http://golang.org/doc/install/source
Reply all
Reply to author
Forward
0 new messages