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

Compiling for Windows (on Linux) emits warnings #552

Open
lordspace opened this issue Dec 28, 2022 · 7 comments
Open

Compiling for Windows (on Linux) emits warnings #552

lordspace opened this issue Dec 28, 2022 · 7 comments

Comments

@lordspace
Copy link

Building for Windows 64b
GOOS=windows GOARCH=amd64 go build -o "$APP_PROJECT_BIN_DIR/${APP_PROJECT_NAME}.exe" -ldflags="-s -w" main.go

`

github.com/go-vgo/robotgo

/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:30:29: undefined: hook.Event
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:31:14: undefined: hook.Start
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:36:7: undefined: hook.End
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:43:24: undefined: hook.Event
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:44:14: undefined: hook.Start
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:60:36: undefined: hook.Event
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:65:69: undefined: hook.Event
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/img.go:92:40: undefined: Bitmap
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/img.go:107:38: undefined: Bitmap
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/img.go:137:20: undefined: Bitmap
/home/qs/go/pkg/mod/github.com/go-vgo/[email protected]/hook.go:44:14: too many errors
`

go version go1.19.4 linux/amd64

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal
@lordspace
Copy link
Author

Actually, it doesn't work on Linux either.

@farmer-simon
Copy link

How did this problem ultimately be solved?

@lordspace
Copy link
Author

Changed the logic of my app and didn't have to use this module.

@wilon
Copy link
Collaborator

wilon commented Aug 4, 2023

Test gcc -v and go env | grep CGO_ENABLED in your enviroment.
I have met the same problems.
Reason:

  • GCC is not installed
  • Or GCC hasn't been added to the environment variable
  • Or go env CGO_ENABLED=0

The solution is to install gcc and add it to the environment variable and set go env -w CGO_ENABLED=1. Refer to https://github.com/go-vgo/robotgo#requirements

By the way, I encountered another issue with Win+VSCode+Git Bash, where certain methods were showing as non-existent in the editor, while some others existed. The reason was that I added GCC to the PATH in Git Bash but not in the system, which caused gopls to be unable to resolve these methods. Add GCC to the system environment variable resolved the issue.

@HackerWand
Copy link

@wilon I try go env -w CGO_ENABLED=0,But still reporting an error

# github.com/go-vgo/robotgo
../../go/pkg/mod/github.com/go-vgo/[email protected]/img.go:92:40: undefined: Bitmap
../../go/pkg/mod/github.com/go-vgo/[email protected]/img.go:107:38: undefined: Bitmap
../../go/pkg/mod/github.com/go-vgo/[email protected]/img.go:137:20: undefined: Bitmap
../../go/pkg/mod/github.com/go-vgo/[email protected]/screen.go:26:28: undefined: Rect
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:9:2: undefined: Move
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:17:2: undefined: Toggle
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:18:2: undefined: MilliSleep
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:20:2: undefined: MoveSmooth
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:21:2: undefined: Toggle
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:29:9: undefined: MoveSmooth
../../go/pkg/mod/github.com/go-vgo/[email protected]/robotgo_fn_v1.go:29:9: too many errors
go env | grep CGO_ENABLED
CGO_ENABLED="0"

use go env -w CGO_ENABLED=1

# Building target: windows/arm64

  • Generating bindings: Done.
  • Installing frontend dependencies: Done.
  • Compiling frontend: Done.
  • Generating application assets: Done.
  • Compiling application: # runtime/cgo
gcc_libinit_windows.c:8:10: fatal error: 'windows.h' file not found

@f-dong f-dong mentioned this issue Apr 19, 2024
2 tasks
@Senriakane123

This comment was marked as resolved.

@DehaiWang
Copy link

i build for windows in Ubuntu ,

sudo apt-get install mingw-w64

GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -o main.exe

it works

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

6 participants