go - 编译到安卓
问题描述
我写了下面的代码build.go
来自动化交叉编译过程,但它失败Android
了,可能是什么原因:
package main
import (
"fmt"
"os"
"os/exec"
)
type compiles struct {
sys string
arch string
}
func main() {
var output string
// go tool dist list
systems := []compiles{
compiles{
sys: "darwin",
arch: "amd64",
},
compiles{
sys: "android",
arch: "amd64",
},
compiles{
sys: "linux",
arch: "amd64",
},
compiles{
sys: "windows",
arch: "amd64",
},
}
for _, s := range systems {
os.Setenv("GOOS", s.sys)
os.Setenv("GOARCH", s.arch)
switch println(s.sys); s.sys {
case "darwin":
output = "output.dmg"
case "windows":
output = "output.exe"
case "android", "linux":
output = "output"
default:
println("Undefined")
}
cmd := exec.Command("go", "build", "-o", output, "main.go")
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("cmd.Run() failed with %v:\n\noutput:\n\n%s\n", err, out)
}
}
}
我得到以下输出:
C:\Users\hasan\Documents\GoPlay\Env>go run build.go
darwin
android
cmd.Run() failed with exit status 2:
output:
# command-line-arguments
c:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
gcc: error: unrecognized command line option '-rdynamic'
linux
windows
我在 Mac OS 上也试过,得到:
cmd.Run() failed with exit status 2:
output:
# command-line-arguments
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)
并在 Linux(Win10 上的 Ubuntu WSL)上尝试并得到:
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-178415548/go.o:(.data+0x0): undefined reference to `x_cgo_callers'
/tmp/go-link-178415548/go.o:(.data+0x8): undefined reference to `x_cgo_init'
/tmp/go-link-178415548/go.o:(.data+0x10): undefined reference to `x_cgo_mmap'
/tmp/go-link-178415548/go.o:(.data+0x18): undefined reference to `x_cgo_munmap'
/tmp/go-link-178415548/go.o:(.data+0x20): undefined reference to `x_cgo_notify_runtime_init_done'
/tmp/go-link-178415548/go.o:(.data+0x28): undefined reference to `x_cgo_sigaction'
/tmp/go-link-178415548/go.o:(.data+0x30): undefined reference to `x_cgo_thread_start'
/tmp/go-link-178415548/go.o:(.data+0x38): undefined reference to `x_cgo_setenv'
/tmp/go-link-178415548/go.o:(.data+0x40): undefined reference to `x_cgo_unsetenv'
/tmp/go-link-178415548/go.o:(.data+0x48): undefined reference to `_cgo_yield'
collect2: error: ld returned 1 exit status
解决方案
推荐阅读
- javascript - 进度条充当导航栏上的边框底部
- autoit - 输入框和案例,取消或关闭窗口
- azure - Azure 和绘图数据
- javascript - 从 MVC 中的 JavaScript 调用带有字符串类型参数的操作
- css - 在 CSS Grid 中相互流动的元素
- javascript - React Native Expo 推送通知重定向无法正常工作
- pandas - pandas 将 Series 转换为 DataFrame 而没有“dtype”信息
- regex - 选择不在两个表达式之间的字符 (:)
- jquery - 悬停特定时间后如何触发功能?
- c++ - 将 QMultiSampleAntiAliasing 添加到 QForwardRenderer