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

Cross Compilation(Linux->Win) error #228

Closed
3 tasks
EnochTheWise opened this issue Sep 9, 2019 · 5 comments
Closed
3 tasks

Cross Compilation(Linux->Win) error #228

EnochTheWise opened this issue Sep 9, 2019 · 5 comments
Labels
Milestone

Comments

@EnochTheWise
Copy link

EnochTheWise commented Sep 9, 2019

  • 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

...

@ghost
Copy link

ghost commented Sep 16, 2019

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

@berkant
Copy link

berkant commented Nov 25, 2019

Same problem.

@berkant
Copy link

berkant commented Nov 25, 2019

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.

https://wiki.openttd.org/Cross-compiling_for_Windows#zlib

@vcaesar
Copy link
Member

vcaesar commented Nov 28, 2019

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.

@walkeralencar
Copy link

walkeralencar commented Jul 30, 2020

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:

I hope that help someone.

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

No branches or pull requests

4 participants