如何解决Cgo“未定义参考”gstreamer
我正在使用cgo编写一些东西来与gstreamer-1.0库进行交互。我的所有工作几乎都可以正常运行,但是由于某种原因,整个头文件的对象无法正确导入。
go version go1.15.2 linux/amd64
进行任何有价值的操作
package main
// #cgo pkg-config: gstreamer-1.0
// #cgo CFLAGS: -Wno-deprecated-declarations
// #include <gst/gst.h> // using this file extensively with no issues
// #include <gst/app/gstappsink.h> // objects in this file are not getting read,but the compiler is having no issue reading it
import "C"
func init () { C.gst_init(nil,nil) }
func main () {
// ...
C.gst_app_sink_pull_sample() // a non-variadic function that does take args
// but cgo doesn't even think it exists.
// ...
}
从编译器返回的错误:/tmp/go-build/cgo-gcc-prolog:64: undefined reference to 'gst_app_sink_pull_sample'
我已经查看了头文件,并且确实存在gst_app_sink_pull_sample
。我既可以尝试在本地也可以在golang
docker容器中进行构建。
如果我完全删除include
,则错误将有所不同:Could not determine kind of name for C.gst_app_sink_pull_sample
。
那么我是问题还是gstreamer问题?
解决方法
appsrc和appsink符号不属于基本gstreamer库。而是在额外的库gstreamer-app-1.0
中找到它们。将此库添加到您的cgo pkgconfig行中,它应该找到缺少的符号。
“对xxx的未定义引用”表示cgo的C编译器可以识别定义,但是找不到实现(由相应的C库覆盖)
这表明您已正确导入C头文件。要解决未定义的引用问题,如果动态库名为libgstreamer.so.1.0.0
,则只需添加以下内容# cgo LDFLAGS: -lgstreamer
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。