libvirt-go在macOS上使用GOOS=Linux进行交叉编译失败。

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

libvirt-go cross-compiling fails on macos with the GOOS=Linux

问题

我有一个使用libvirt-go v7.4.0的项目。

go.mod:

github.com/libvirt/libvirt-go v7.4.0+incompatible // indirect

它在Mac和Linux上都可以编译,但是在MacOS上使用GOOS=Linux标志进行交叉编译会失败。

$ env GOOS=linux go build -o myapp .
# gitlab.mycompany.io/mycompany-platform/myapp/command/agent
command/agent/libvirt_listener.go:11:26: undefined: libvirt.DomainEventType
command/agent/libvirt_listener.go:23:14: undefined: libvirt.Connect
command/agent/libvirt_listener.go:100:9: undefined: libvirt.EventRegisterDefaultImpl
command/agent/libvirt_listener.go:105:15: undefined: libvirt.NewConnect
command/agent/libvirt_listener.go:115:4: undefined: libvirt.EventRunDefaultImpl
command/agent/libvirt_listener.go:121:22: undefined: libvirt.Connect
command/agent/libvirt_listener.go:121:42: undefined: libvirt.Domain
command/agent/libvirt_listener.go:121:65: undefined: libvirt.DomainEventLifecycle
command/agent/libvirt_listener.go:149:63: undefined: libvirt.DomainState
command/agent/libvirt_listener.go:121:22: too many errors

英文:

I have a project using libvirt-go v7.4.0.

go.mod:

github.com/libvirt/libvirt-go v7.4.0+incompatible // indirect

It compiles on both mac and linux, but cross-compiling fails on macos with the GOOS=Linux flag.

$ env GOOS=linux go build -o myapp .
# gitlab.mycompany.io/mycompany-platform/myapp/command/agent
command/agent/libvirt_listener.go:11:26: undefined: libvirt.DomainEventType
command/agent/libvirt_listener.go:23:14: undefined: libvirt.Connect
command/agent/libvirt_listener.go:100:9: undefined: libvirt.EventRegisterDefaultImpl
command/agent/libvirt_listener.go:105:15: undefined: libvirt.NewConnect
command/agent/libvirt_listener.go:115:4: undefined: libvirt.EventRunDefaultImpl
command/agent/libvirt_listener.go:121:22: undefined: libvirt.Connect
command/agent/libvirt_listener.go:121:42: undefined: libvirt.Domain
command/agent/libvirt_listener.go:121:65: undefined: libvirt.DomainEventLifecycle
command/agent/libvirt_listener.go:149:63: undefined: libvirt.DomainState
command/agent/libvirt_listener.go:121:22: too many errors

答案1

得分: 1

libvirt-go包是对本地libvirt平台库的CGo绑定。因此,在构建时无法禁用CGO,进而无法进行交叉编译,因为交叉编译会隐式禁用CGO。

英文:

THe libvirt-go package is a CGo binding to the native libvirt platform library. As such it is not possible to disable CGO when building it, and in turn it is not possible to cross-compile as that implicitly disables CGO.

huangapple
  • 本文由 发表于 2021年8月28日 01:49:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/68957556.html
匿名

发表评论

匿名网友

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

确定