交叉编译:”用户:当前在linux/amd64上尚未实现”

huangapple go评论68阅读模式
英文:

Cross compiling: "user: Current not implemented on linux/amd64"

问题

我在一个linux/amd64的机器上编译了以下Go程序:

package main

import (
	"fmt"
	"os/user"
)

func main() {
	fmt.Println(user.Current())
}

这个程序可以正常工作。但是当我从Mac机器上进行交叉编译,并在我的linux机器上运行该程序时,我得到了以下错误:

user: Current not implemented on linux/amd64

我该如何进行交叉编译并使用os/user包中的Current函数?


编辑1:
我应该补充说明,这些是我在Mac机器上设置交叉编译的指令:https://code.google.com/p/go-wiki/wiki/WindowsCrossCompiling


编辑2:为windows/386进行交叉编译可以正常工作。

英文:

I compile the following Go program on a linux/amd64 box:

package main

import (
	"fmt"
	"os/user"
)

func main() {
	fmt.Println(user.Current())
}

This works fine. But when I cross compile it from a Mac box, I get the following error when I run that program on my linux box:

user: Current not implemented on linux/amd64

How can I cross compile and use the Current function in package os/user?


Edit 1:
I should add that these are the instructions I've used to setup cross compiling on my Mac box: https://code.google.com/p/go-wiki/wiki/WindowsCrossCompiling


Edit 2: cross compiling for windows/386 works fine.

答案1

得分: 19

这是由于问题 6376:在从 Linux-amd64 交叉编译到 darwin-amd64 时,user.Current 在 darwin-amd64 上引发 panic

>os/user 依赖于 cgo,在交叉编译时会禁用 cgo,因此这是预期的。

>如果你使用 os/user,你必须在 macOS 上进行本地编译。

>即使我们启用了交叉编译的 cgo 支持,我怀疑每个人都在他们的 Linux 机器上拥有一个可用的 macOS 交叉工具链。

>状态:按设计工作

英文:

This is due to Issue 6376: user.Current panic in darwin-amd64 when crosscompiled from linux-amd64:

>os/user relies on cgo, and cgo is disabled for cross compiling,
thus this is expected.

>if you use os/user, you must compile natively on OS X.

>even if we enable cross compilation cgo support, I doubt everybody have
a working OS X cross toolchain on their linux machine.

>Status: WorkingAsIntended

huangapple
  • 本文由 发表于 2013年12月16日 19:08:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/20609415.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定