首先安装windwos系统的一些编译环境:MinGW-w64
1.使用Homebrew进行安装Mingw
brew install mingw-w64
如果出现如下报错:
Warning: You are using macOS 15.
We do not provide support for this pre-release version.
It is expected behaviour that some formulae will fail to build in this pre-release version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew’s GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew’s discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.
Error: unknown or unsupported macOS version: :dunno
那么执行如下指令,需要挂🪜
brew update-reset
然后重新执行刚才的安装命令,安装好了之后检查一下是否安装成功
x86_64-w64-mingw32-gcc --version
2.编写代码
package main
import (
"fmt"
"github.com/go-vgo/robotgo"
)
func main() {
// 移动鼠标到指定位置
robotgo.Move(100, 200)
fmt.Println("鼠标已移动到(100, 200)位置")
}
3.编译
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build