英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论