Cgo "undefined reference" (gstreamer)
Cgo "undefined reference" (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 行,它应该会找到缺少的符号。
“undefined reference to xxx”表示cgo的C编译器识别定义但找不到实现(由相应的C库覆盖)
这表明您已正确导入 C 头文件。要解决未定义的引用问题,如果你的动态库调用 libgstreamer.so.1.0.0
,你只需要添加如下内容
# cgo LDFLAGS: -lgstreamer
我正在使用 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 行,它应该会找到缺少的符号。
“undefined reference to xxx”表示cgo的C编译器识别定义但找不到实现(由相应的C库覆盖)
这表明您已正确导入 C 头文件。要解决未定义的引用问题,如果你的动态库调用 libgstreamer.so.1.0.0
,你只需要添加如下内容# cgo LDFLAGS: -lgstreamer