Skip to content
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

Unable to build application for linux on windows machine #40129

Closed
rakeshrvce opened this issue Jul 9, 2020 · 13 comments
Closed

Unable to build application for linux on windows machine #40129

rakeshrvce opened this issue Jul 9, 2020 · 13 comments

Comments

@rakeshrvce
Copy link

@rakeshrvce rakeshrvce commented Jul 9, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.6 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\krr\AppData\Local\go-build
set GOENV=C:\Users\krr\AppData\Roaming\go\env
set GOEXE=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=linux
set GOPATH=C:\Users\krr\go;
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\RakeshKR\AG\GO\git_code\go\airgroup\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=-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=C:\Users\krr\AppData\Local\Temp\go-build015935298=/tmp/go-build -gno-record-gcc-switches

What did you do?

On windows mingw-w64 is installed for gcc and CGO_ENABLED is set to 1 which is needed for confluent-kafka-go library.
I am trying to build the application(which internally uses this library) for ubuntu on windows machine but compilation is failing.
compilation command: go build -o packet-handler myapp/main.go

What did you expect to see?

Application compiling successfully

What did you see instead?

$ go build -o packet-handler myapp/main.go
runtime/cgo
gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
gcc_linux_amd64.c:61:2: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
sigset_t ign, oset;
^~~~~~~~
_sigset_t
gcc_linux_amd64.c:66:2: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
sigfillset(&ign);
^~~~~~~~~~
gcc_linux_amd64.c:61:16: error: unused variable 'oset' [-Werror=unused-variable]
sigset_t ign, oset;
^~~~
cc1.exe: all warnings being treated as errors

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jul 9, 2020

Is your C compiler targeting Linux? You need a C cross compiler that targets Linux, and set CC environment variable to its path.

@rakeshrvce
Copy link
Author

@rakeshrvce rakeshrvce commented Jul 9, 2020

If you look at my go env, cc is set to gcc and I am using following gcc verison:
$ gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 9, 2020

That C compiler targets mingw, not GNU/Linux.

In order to build a GNU/Linux program on WIndows, with CGO_ENABLED=1, you need to have a cross-compiler that targets GNU/Linux.

Closing because while the situation is unfortunate, there isn't really anything we can do in the Go toolchain to fix this. To build C code that runs on GNU/Linux you must have a C compiler that produces GNU/Linux code.

@rakeshrvce
Copy link
Author

@rakeshrvce rakeshrvce commented Jul 9, 2020

Is there any way I can make C compiler targets to GNU on windows?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 9, 2020

Sure, but we are the wrong people to ask about that. A web search for "cross compile from windows to linux" pulls up a number of promising pages.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jul 10, 2020

Is there any way I can make C compiler targets to GNU on windows?

I do not know. Maybe try

http://musl.cc/

Perhaps, @zv-io, can help.

but we are the wrong people to ask about that. A web search for "cross compile from windows to linux" pulls up a number of promising pages.

I am not sure we should be the wrong people. If we support Mingw on Windows, we should provide link to download the tools. gcc is never installed on Windows, and Windows users rarely know what it is and how to install it. See, for example, #35006 (comment)

Alex

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 10, 2020

@alexbrainman I think the use of the word "GNU" was confusing here. This issue here isn't getting a GNU compiler that runs on Windows and generates programs that run on Windows. It's about getting a compiler that runs on Windows and generates programs that run on GNU/Linux.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jul 11, 2020

It's about getting a compiler that runs on Windows and generates programs that run on GNU/Linux.

I understand what you meant, Ian. I suspect there is a version of gcc that runs on Windows and generates Linux binaries. It might be listed on http://musl.cc/

Alex

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 11, 2020

Ah, OK, sorry.

@zv-io
Copy link

@zv-io zv-io commented Jul 12, 2020

@ianlancetaylor @alexbrainman The toolchains at https://musl.cc/ are capable of at least:

If others are needed, just let me know.

@rakeshrvce
Copy link
Author

@rakeshrvce rakeshrvce commented Jul 13, 2020

I need it for windows 10 machine to ubuntu 18(i.e. windows to linux). Should i pick this one x86_64-linux-musl-cross.zip ?
What is the naming format followed to name the these file on https://win.musl.cc/ ? How to read these file?

@zv-io
Copy link

@zv-io zv-io commented Jul 13, 2020

I need it for windows 10 machine to ubuntu 18(i.e. windows to linux). Should i pick this one x86_64-linux-musl-cross.zip ?

Yes, that is correct.

What is the naming format followed to name the these file on https://win.musl.cc/ ? How to read these file?

Anything that is a .zip file will run on Windows, so the name is the target platform. For example, x86_64-linux-musl produces binaries built for x86_64 Linux.

I do not know if this will work for your intended purpose (it may require fiddling with environment variables and build flags, for example using -static because Ubuntu is based on glibc and not musl libc).

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jul 14, 2020

@ianlancetaylor @alexbrainman The toolchains at https://musl.cc/ are capable of at least:

Thanks for your help, @zv-io.

@ianlancetaylor can we refer users to this website for pre-built Mingw binaries? I think this will be helpful to Windows cgo users.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.