在CentOS中,使用Golang实现跨平台编译非常简单。你只需要设置GOOS和GOARCH环境变量,然后运行go build命令即可。下面是一些常见的操作系统和架构组合:
GOOS=windows GOARCH=amd64 go build -o your_app.exe GOOS=darwin GOARCH=amd64 go build -o your_app_mac GOOS=linux GOARCH=amd64 go build -o your_app_linux GOOS=linux GOARCH=386 go build -o your_app_linux_32 GOOS=linux GOARCH=arm64 go build -o your_app_linux_arm64 你可以根据需要替换your_app为你的应用程序名称。如果你需要为其他平台和架构构建,请查阅Golang官方文档以获取更多信息。
注意:在某些情况下,你可能还需要设置CGO_ENABLED=0来禁用cgo,以确保生成的可执行文件不依赖于C库。例如:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o your_app_linux