micmonay / keybd_event

For simulate key press in Linux, Windows and Mac in golang
MIT License
380 stars 57 forks source link

Unable to compile on some platforms #2

Closed odino closed 5 years ago

odino commented 8 years ago

Im using this library in a project but I cant seem to get it compiled for som platforms:

root@5c3afb402c7b:/go/src/github.com/odino/touchy# env GOOS=darwin GOARCH=amd64 go build -v github.com/odino/touchy
runtime
math
errors
unicode/utf8
sync/atomic
unicode
crypto/subtle
sort
sync
container/list
io
syscall
hash
hash/crc32
crypto/cipher
crypto/hmac
bytes
strings
strconv
bufio
time
math/rand
internal/singleflight
path
encoding
unicode/utf16
github.com/micmonay/keybd_event
reflect
crypto
# github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

ie. this is the output using gox:

Number of parallel builds: 3

-->      netbsd/arm: github.com/odino/touchy
-->      darwin/386: github.com/odino/touchy
-->    darwin/amd64: github.com/odino/touchy
-->     openbsd/386: github.com/odino/touchy
-->       linux/386: github.com/odino/touchy
-->     linux/amd64: github.com/odino/touchy
-->       linux/arm: github.com/odino/touchy
-->     freebsd/386: github.com/odino/touchy
-->   freebsd/amd64: github.com/odino/touchy
-->   windows/amd64: github.com/odino/touchy
-->   openbsd/amd64: github.com/odino/touchy
-->     windows/386: github.com/odino/touchy
-->      netbsd/386: github.com/odino/touchy
-->     freebsd/arm: github.com/odino/touchy
-->    netbsd/amd64: github.com/odino/touchy

12 errors occurred:
--> darwin/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> darwin/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> netbsd/arm error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> openbsd/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> linux/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> linux/arm error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> freebsd/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> freebsd/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> openbsd/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> netbsd/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> freebsd/arm error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD

--> netbsd/amd64 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
micmonay commented 8 years ago

I try tomorrow... :) I have the same troble (Sorry if my english is bad)

odino commented 8 years ago

No worries, your english is good!

Let me know if you have any news, it's such a weird error :-S

micmonay commented 8 years ago

Hi I do build on my mac os x (10.11.2) it's ok. But cross compilation in linux isn't ok. Bugs probably come on C code in file keybd_darwin.go My skills is not good for find other way

In header keybd_darwin.go is compiled :

 #cgo CFLAGS: -x objective-c
 #cgo LDFLAGS: -framework Cocoa
 #import <Foundation/Foundation.h>
 CGEventRef Create(int k){
    CGEventRef event = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)k, true);
    return event;
 }
 void KeyTap(CGEventRef event){
    CGEventPost(kCGAnnotatedSessionEventTap, event);
    CFRelease(event);
 }
 void AddActionKey(CGEventFlags type,CGEventRef event){
    CGEventSetFlags(event, type);
}

It's possible same troble for gox

odino commented 8 years ago

Actually I dont think it's C specific, as I can see it not compiling under some linux archs as well:

--> linux/386 error: exit status 2
Stderr: # github.com/micmonay/keybd_event
../../micmonay/keybd_event/keybd_event.go:22: undefined: initKeyBD
micmonay commented 8 years ago

I have updated for your project touchy, because keys having not same name. I have testing your project on mac os x it is ok for me. But cross compilation I don't know why it is crashing. I find a solution... but I don't have a long experience in GOLANG

micmonay commented 8 years ago

Hard ! I found and I have a first solution for linux x86 but no for darwin

env CGO_ENABLED=1 gox [project]

Trouble comes from cgo, some files are ignored. I don't know why exactly ^^

odino commented 8 years ago

Oh that's nice! Let me try it!

TrashPony commented 6 years ago

Hi, for linux/arm of Debian 9 solution: apt-get install gcc-arm-linux-gnueabi env GOOS=linux GOARCH=arm CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 go build ./main.go