Cross Compilation(Linux->Win) error
EnochTheWise opened this issue · comments
- Robotgo version (or commit ref): current master
- Go version: go version go1.12.9 linux/amd64
- Gcc version: gcc (Debian 9.2.1-4) 9.2.1 20190821 / x86_64-w64-mingw32-gcc (GCC) 8.3-win32 20190709
- Operating system and bit: Debian bullseye/sid
- Resolution: console
- Can you reproduce the bug at Examples:
- Yes (provide example code)
- No
- Not relevant
- Provide example code:
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"math/rand"
"github.com/go-vgo/robotgo"
)
// SetupCloseHandler creates a 'listener' on a new goroutine which will notify the
// program if it receives an interrupt from the OS. We then handle this by calling
// our clean up procedure and exiting the program.
func SetupCloseHandler() {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("\r- Ctrl+C pressed in Terminal")
os.Exit(0)
}()
}
func main() {
// Setup our Ctrl+C handler
SetupCloseHandler()
fmt.Println("\r- Press Ctrl+C to interrupt")
// Run our program...
for {
rand.Seed(time.Now().UnixNano())
min := 120
max := 480
sleep_secs := rand.Intn(max - min + 1) + min
fmt.Println("\r- Type key and sleep: ", sleep_secs, "sec's")
robotgo.ActiveName("KWrite")
robotgo.TypeString("Hello World")
robotgo.KeyTap("space")
time.Sleep(time.Duration(sleep_secs) * time.Second)
}
}
- Log gist:
$ GOOS=windows GOARCH=amd64 go build -o sendkey.exe sendkey.go
# github.com/go-vgo/robotgo
../../github.com/go-vgo/robotgo/keycode.go:14:16: undefined: Map
../../github.com/go-vgo/robotgo/keycode.go:25:15: undefined: Map
../../github.com/go-vgo/robotgo/robotgo_mac_win.go:22:9: undefined: internalGetBounds
../../github.com/go-vgo/robotgo/robotgo_mac_win.go:31:12: undefined: cgetTitle
../../github.com/go-vgo/robotgo/robotgo_mac_win.go:45:2: undefined: internalActive
$ GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -o sendkey-amd64.exe sendkey.go
# github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook
/usr/bin/x86_64-w64-mingw32-ld: $WORK/b042/_x003.o: in function `eb_port_create':
../../github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook/event/../chan/eb_chan.h:382: undefined reference to `sched_yield'
/usr/bin/x86_64-w64-mingw32-ld: $WORK/b042/_x003.o: in function `eb_port_free':
../../github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook/event/../chan/eb_chan.h:350: undefined reference to `sched_yield'
/usr/bin/x86_64-w64-mingw32-ld: ../../github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook/event/../chan/eb_chan.h:341: undefined reference to `sched_yield'
/usr/bin/x86_64-w64-mingw32-ld: $WORK/b042/_x003.o: in function `cleanup_ops':
../../github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook/event/../chan/eb_chan.h:858: undefined reference to `sched_yield'
/usr/bin/x86_64-w64-mingw32-ld: ../../github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook/event/../chan/eb_chan.h:858: undefined reference to `sched_yield'
/usr/bin/x86_64-w64-mingw32-ld: $WORK/b042/_x003.o:/home/john/work/go-lang/src/github.com/go-vgo/robotgo/vendor/github.com/robotn/gohook/event/../chan/eb_chan.h:643: more undefined references to `sched_yield' follow
collect2: error: ld returned 1 exit status
Description
...
i have same problem.
- Robotgo version (or commit ref): current master
- Go version: go version go1.12.9 darwin/amd64
- Gcc version: x86_64-w64-mingw32-gcc (GCC) 9.1.0
- Operating system and bit: MacOS Mojave 10.14.5
- Resolution: console
Same problem.
I may have fixed this in Go 1.13. At least it works when cross compiling from Linux to Windows.
env GOOS=windows \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC=x86_64-w64-mingw32-gcc-posix \
CXX=x86_64-w64-mingw32-g++-posix \
CGO_CFLAGS="`go env CGO_CFLAGS` -I/usr/local/x86_64-w64-mingw32/include" \
CGO_LDFLAGS="`go env CGO_LDFLAGS` -L/usr/local/x86_64-w64-mingw32/lib -L/usr/local/x86_64-w64-mingw32/lib" \
go build -x -trimpath -ldflags="-w -s -extldflags -static"
But first you have to install zlib from source.
Thanks for your feedback; I cannot answer every question because time is limited, other features and projects are being developing, and the computer equipment and environment configuration are different.
hey guys, after some research and a lot of waste of time, finally is running for me.
Required:
sudo apt-get install gcc-multilib
sudo apt-get install gcc-mingw-w64
Created a file: winbuild.sh with following content:
#!/bin/bash
export GOOS=windows
export GOARCH=386
export CC=i686-w64-mingw32-gcc
export CXX=i686-w64-mingw32-g++
export CGO_ENABLED=1
export CGO_CXXFLAGS="-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic"
go build -ldflags "-s -w -X main.version=$2" -o $3 -v -x $1
how to use:
$ ./winbuild.sh main.go 1.0.0 sendkey-i686.exe
or
$ ./winbuild.sh ./ 1.0.0 sendkey-i686.exe
Need to attach a zlib1.dll when you make zip or installer.
References:
- #143
- #235
- https://stackoverflow.com/questions/41566495/golang-how-to-cross-compile-on-linux-for-windows
I hope that help someone.