简体   繁体   English

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

[英]cgo cross compiling from amd64(linux) to arm64(linux)

I am trying to build a go code for "arm64" architecture from "amd64" using a arm64 based so. 我试图使用基于arm64的“ amd64”构建“ arm64”架构的go代码。 I get the below mentioned error when I build the go code with the shared library. 使用共享库构建go代码时,出现以下错误。 Can someone please assist me on this? 有人可以帮我吗?

Go Version: go1.10.3 linux/amd64 Go版本:go1.10.3 linux / amd64

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

go env: 去env:

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

Error: go build hello.go 错误:建立hello.go

# 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],'

Go Code: 验证码:

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")
}

I linked the math library like so #cgo LDFLAGS: -L./cgolang/lib -lpthread -lm 我像这样#cgo LDFLAGS链接了数学库:-L./cgolang/lib -lpthread -lm

That worked for me. 那对我有用。 If your shared library is provided by a third party, please ask them to help you out 如果您的共享库是由第三方提供的,请让他们帮助您

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 cgo 从 linux/amd64 交叉编译到 darwin/arm64? - How to cross-compile from linux/amd64 to darwin/arm64 with cgo? 无法在 AMD64 Linux 上模拟 Android ARM64 - Cannot emulate Android ARM64 on AMD64 Linux 警告:请求的图像平台 (linux/amd64) 与检测到的主机平台 (linux/arm64/v8) 不匹配 - WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) 在amd64上运行arm64的macOS中的docker - docker in macOS running arm64 on amd64 如何在Ubuntu中使用arm-linux-gnueabihf-g ++在amd64系统上交叉编译32位arm体系结构的应用程序 - How to cross compile application for 32 bit arm architecture on amd64 system using arm-linux-gnueabihf-g++ in Ubuntu 从shell杀死linux套接字(gentoo amd64) - Killing linux socket from shell (gentoo amd64) 如何使用linux amd64,cmake和g ++交叉编译linux x86? - How to cross compile for linux x86 with linux amd64, cmake and g++? spotifyd,交叉编译arm64 - spotifyd, cross compiling for arm64 如何在高山Linux中获得docker体系结构,例如amd64,arm32v7? - How to get docker architecture, like amd64, arm32v7, in alpine linux? 当我的PC具有ARM64架构时,安装为AMD64开发的软件package - Installing software package developed for AMD64 when my PC has ARM64 architecture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM