我正在尝试使用基于arm64的so从“amd64”为“arm64”体系结构构建go代码。当我用共享库构建go代码时,出现了下面提到的错误。有人能帮我一下吗?
Go版本:
GO1.10.3 Linux/AMD64
GCC版本:
gcc 7.3.0版(ubuntu 7.3.0-21ubuntu1~16.04)
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],'

执行代码:
package main
/*
#cgo CFLAGS: -I./cgolang/include
#cgo LDFLAGS: -L./cgolang/lib  -laxxxxxx
#include "axxxxxx.h"
*/
import "C"
import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

最佳答案

我链接了数学库,如so cgo ldflags:-l./cgolang/lib-lpthread-lm
这对我很有用。
如果您的共享库是由第三方提供的,请让他们帮助您

关于linux - cgo从amd64(linux)交叉编译到arm64(linux),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51475992/

10-13 03:10