cgo从amd64(linux)交叉编译到arm64(linux)

时间:2018-07-23 09:53:18

标签: linux cross-compiling cgo gccgo

我正在尝试使用基于arm64的“ amd64”为“ arm64”架构构建go代码。使用共享库构建go代码时,出现以下错误。有人可以帮我吗?

转到版本: go1.10.3 linux / amd64

gcc版本: gcc版本7.3.0(Ubuntu 7.3.0-21ubuntu1〜16.04)

转到环境:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div style="background:black; width:100px; height:100px; padding:20px;">
  <p style="color:white;">on/off button:</p>
  <label class="switch">
    <input name="saveee" type="checkbox">
    <span class="slider round"></span>
  </label>
</div>

错误: 去建立hello.go

GOARCH="arm64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
CGO_ENABLED="1"

执行代码:

# runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:27: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:28: Error: no such instruction: `stp x21,x22,[sp,'
gcc_arm64.S:29: Error: no such instruction: `stp x23,x24,[sp,'
gcc_arm64.S:30: Error: no such instruction: `stp x25,x26,[sp,'
gcc_arm64.S:31: Error: no such instruction: `stp x27,x28,[sp,'
gcc_arm64.S:32: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:33: Error: too many memory references for `mov'
gcc_arm64.S:35: Error: too many memory references for `mov'
gcc_arm64.S:36: Error: too many memory references for `mov'
gcc_arm64.S:37: Error: too many memory references for `mov'
gcc_arm64.S:39: Error: no such instruction: `blr x20'
gcc_arm64.S:40: Error: no such instruction: `blr x19'
gcc_arm64.S:42: Error: no such instruction: `ldp x29,x30,[sp],'
gcc_arm64.S:43: Error: no such instruction: `ldp x27,x28,[sp],'
gcc_arm64.S:44: Error: no such instruction: `ldp x25,x26,[sp],'
gcc_arm64.S:45: Error: no such instruction: `ldp x23,x24,[sp],'
gcc_arm64.S:46: Error: no such instruction: `ldp x21,x22,[sp],'
gcc_arm64.S:47: Error: no such instruction: `ldp x19,x20,[sp],'

2 个答案:

答案 0 :(得分:0)

我像这样#cgo LDFLAGS链接了数学库:-L./cgolang/lib -lpthread -lm

对我有用。 如果您的共享库是由第三方提供的,请让他们帮助您

答案 1 :(得分:0)

env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=/path/to/your/arm64/gcc go build hello.go

您可能会看到同样的问题:https://github.com/golang/go/issues/8161