aizimmer
aizimmer

Reputation: 1213

Cgo "undefined reference" (gstreamer)

I am writing something using cgo to interact with the gstreamer-1.0 library. I have everything almost working perfectly, but for some reason an entire header file's objects are not getting imported correctly.

go version go1.15.2 linux/amd64 for whatever that is worth

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.
  // ...
}

The error back from the compiler: /tmp/go-build/cgo-gcc-prolog:64: undefined reference to 'gst_app_sink_pull_sample'

I've looked at the header file and gst_app_sink_pull_sample is indeed there. I can reproduce this both trying to build locally and in the golang docker container.

If I remove the include entirely the error is different: could not determine kind of name for C.gst_app_sink_pull_sample.

So am I the problem or is gstreamer the problem?

Upvotes: 0

Views: 1595

Answers (2)

Scherzando
Scherzando

Reputation: 92

"undefined reference to xxx" means the C compiler of cgo recognize the definitions but it can't find the implementations (covered by corresponding C libraries)

This indicates that you have your C header files imported correctly. To solve the undefined reference problem, you just have to add some thing as below if your dynamic library is called libgstreamer.so.1.0.0

# cgo LDFLAGS: -lgstreamer

Upvotes: 1

Florian Zwoch
Florian Zwoch

Reputation: 7373

The appsrc and appsink symbols are not part of the base gstreamer library. Instead they are found in the extra library gstreamer-app-1.0. Add this library to your cgo pkgconfig line and it should find the missing symbols.

Upvotes: 1

Related Questions