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

env GOOS=windows GOARCH=amd64 go build uidemo.go #155

Closed
omac777 opened this issue Jun 19, 2016 · 18 comments
Closed

env GOOS=windows GOARCH=amd64 go build uidemo.go #155

omac777 opened this issue Jun 19, 2016 · 18 comments

Comments

@omac777
Copy link

omac777 commented Jun 19, 2016

Before I start, here is my go version 1.7beta2 environment:
go version
go version devel +fca9fc5 Thu Jun 16 19:45:33 2016 +0000 linux/amd64

go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/loongson/Code"
GORACE=""
GOROOT="/home/loongson/go1.7beta2"
GOTOOLDIR="/home/loongson/go1.7beta2/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build780373348=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

NOTE THE BUILDING NATIVELY WITH JUST go build works and with the following:
env GOOS=linux GOARCH=amd64 go build uidemo.go

GOOD.

CROSS-COMPILING TO WINDOWS 64-BIT HOWEVER FAILS.
It seems I have to be on windows in order for this to compile successfully.

env GOOS=windows GOARCH=amd64 go build uidemo.go

command-line-arguments

./uidemo.go:8: undefined: ui.Main
./uidemo.go:9: undefined: ui.NewEntry
./uidemo.go:10: undefined: ui.NewButton
./uidemo.go:11: undefined: ui.NewLabel
./uidemo.go:12: undefined: ui.NewVerticalBox
./uidemo.go:13: undefined: ui.NewLabel
./uidemo.go:17: undefined: ui.NewWindow
./uidemo.go:19: undefined: ui.Button
./uidemo.go:22: undefined: ui.Window
./uidemo.go:23: undefined: ui.Quit
./uidemo.go:23: too many errors

@andlabs
Copy link
Owner

andlabs commented Jun 19, 2016

You also need to set three additional environment variables when building package ui:

  1. CGO_ENABLED=1
  2. CC=exectuable-of-mingw-w64-gcc
  3. CXX=executable-of-mingw-w64-g++

For instance, on an Ubuntu system with the MinGW-w64 packages in universe it would be

CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++

The problem is that Go doesn't know how to cross compile cgo packages on its own; you have to tell it what compilers to use (and that you have those compilers in the first place).

@omac777
Copy link
Author

omac777 commented Aug 9, 2016

On 08/09/2016 03:25 AM, ringrid wrote:

I have same question, my OS is Fedora 24, and I had installed mingw32 & mingw64.
When I execute command:
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build main.go

the question is:
/usr/local/go/pkg/tool/linux_amd64/link: running x86_64-w64-mingw32-gcc failed: exit status 1
x86_64-w64-mingw32-gcc: error: unrecognized command line option '-rdynamic'

can you help me?

To see all that information and the context in which you're getting the
rror:
go build -v -x -work main.go

From there you can go into the temporary directory where it's trying to
build it and tweak stuff and build it with different switches...whatever
you want to try that's different. At least it shows you what's going on
under the hood. If you want more help, capture all that verbosity into
a file and put the out put into the mailing list.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#155 (comment)

@ringrid
Copy link

ringrid commented Aug 22, 2016

@omac777 It's userful for me, and I had solved my question,It need other two packages: mingw64-gtk3 mingw64-winpthreads-static
Thanks a lot

@andlabs
Copy link
Owner

andlabs commented Aug 22, 2016

You should not need mingw64-gtk3. The Windows code does not use GTK+ at all.

@ringrid
Copy link

ringrid commented Aug 22, 2016

@andlabs yes, thank you. I removed mingw64-gtk3 and compiled succeed. awesome project!

@txthinking
Copy link

@andlabs
How about on MacOS.

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tx/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.3/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sr/ysfcj49s52dg1fdb61fmj7wm0000gn/T/go-build221482393=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$ CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build demo.go
# runtime/cgo
/usr/local/Cellar/go/1.7.3/libexec/src/runtime/cgo/gcc_libinit_windows.c:7:10: fatal error: 'windows.h' file not found

thanks.

@andlabs
Copy link
Owner

andlabs commented Nov 9, 2016

You need to set $CC to a MinGW-w64 cross-compiler. These should exist on OS X; I don't see one in Homebrew...

@txthinking
Copy link

Thanks for your reply.
After i install MinGW-w64 i got this error

$ CGO_ENABLED=1 \
 GOOS=windows GOARCH=amd64 \
 CC=/usr/local/Cellar/mingw-w64/4.0.4/bin/x86_64-w64-mingw32-gcc\ 
 CXX=/usr/local/Cellar/mingw-w64/4.0.4/bin/x86_64-w64-mingw32-g++ \
 go build .
# github.com/andlabs/ui
../../../../andlabs/ui/libui_windows_amd64.a(stddialogs.cpp.obj): In function `msgbox':
E:\github.com\andlabs\libui\build/E:/github.com/andlabs/libui/windows/stddialogs.cpp:113: undefined reference to `__imp_TaskDialog'
collect2: error: ld returned 1 exit status

@sp-joseluis-ledesma
Copy link

sp-joseluis-ledesma commented Dec 9, 2016

Same error here. Crosscompiling from Linux to Windows:

$ export GOOS=windows
$ export GOARCH=amd64
$ export CGO_ENABLED=1
$ export CC=/usr/bin/x86_64-w64-mingw32-gcc
$ export CXX=/usr/bin/x86_64-w64-mingw32-g++
$ go build

vendor/github.com/andlabs/ui/libui_windows_amd64.a(stddialogs.cpp.obj): In function 'msgbox':
E:\github.com\andlabs\libui\build/E:/github.com/andlabs/libui/windows/stddialogs.cpp:113: undefined reference to '__imp_TaskDialog'
collect2: error: ld returned 1 exit status

@andlabs
Copy link
Owner

andlabs commented Dec 9, 2016

You will need to upgrade to MinGW-w64 5.0.

@YamiOdymel
Copy link

After upgraded MinGW-w64 to 6.3.0, The error undefined reference to '__imp_TaskDialog' still exists on macOS 10.12.2

@andlabs
Copy link
Owner

andlabs commented Jan 23, 2017

How are you installing MinGW-w64?

@YamiOdymel
Copy link

Oops, sorry, I double checked the README again, the 6.3.0 is actually the version of gcc, and the MinGW version is still 4.0.6.

@andlabs
Copy link
Owner

andlabs commented Jan 23, 2017

Ah, all right. I do still hope that there aren't still versions of MinGW-w64 5.0 or newer without the patch...

@andlabs
Copy link
Owner

andlabs commented Mar 26, 2018

Merged with #279.

@andlabs andlabs closed this as completed Mar 26, 2018
@Michael-Dixey
Copy link

Michael-Dixey commented May 1, 2018

@andlabs
I know this thread is old, but I'm running into a similar issue when compiling for Linux from Windows:
C:\go_tests\go_cfg_evd>go build -o form_test_linux formtest.go
.\formtest.go:14:9: undefined: ui.Main
.\formtest.go:15:12: undefined: ui.NewEntry
.\formtest.go:16:15: undefined: ui.NewEntry
.\formtest.go:17:15: undefined: ui.NewEntry
.\formtest.go:19:13: undefined: ui.NewButton
.\formtest.go:20:18: undefined: ui.NewLabel
.\formtest.go:21:10: undefined: ui.NewVerticalBox
.\formtest.go:22:14: undefined: ui.NewLabel
.\formtest.go:24:14: undefined: ui.NewLabel
.\formtest.go:26:14: undefined: ui.NewLabel
.\formtest.go:26:14: too many errors

I've already set my GOOS variable to linux, and compiling for Windows from Windows does work correctly. You had previously mentioned these 3 steps for Linux -> Windows:

  1. CGO_ENABLED=1
  2. CC=exectuable-of-mingw-w64-gcc
  3. CXX=executable-of-mingw-w64-g++

What would be the equivalent for Windows -> Linux?
Thanks

@andlabs
Copy link
Owner

andlabs commented May 1, 2018

CGO_ENABLED is the same. CC and CXX are the names of the executables of the cross-compiler toolchain, whatever that is. Yes, that means you will need a separate cross-compiler toolchain. You will also need to have a pkg-config set up for it, and GTK+ available to link to it, and no, the Windows GTK+ will not work, it must be a Linux GTK+ prepared for use with the cross-compiler. I don't know how to do any of that; sorry.

@Michael-Dixey
Copy link

Thanks for the prompt reply, I appreciate the info. It seems it will probably be easier for me to just install these packages on my linux build and build the executable from there :). Thanks!

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

No branches or pull requests

7 participants