I would like to build a simple static binary using libgstreamer. This is the source
#include <gst/gst.h>
#include <stdbool.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
GstElement *pipeline;
GstBus *bus;
GstMessage *msg;
bool video = true;
if (video == true) {
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Build the pipeline */
GError *err = NULL;
pipeline =
gst_parse_launch ("filesrc location=/home/name/Downloads/train160.webm ! matroskademux ! vp8dec ! xvimagesink",
&err);
if (err != NULL) {
printf("error: %s", err->message);
}
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg =
gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Free resources */
if (msg != NULL)
gst_message_unref (msg);
gst_object_unref (bus);
//gst_element_set_state (pipeline, GST_STATE_NULL);
//gst_object_unref (pipeline);
}
return 0;
}
I'm following the instructions in the gst-build repository, and using the command below to configure the build. I'm working on the 1.19.1 tag, commit 3804f23
meson --default-library=static -Dintrospection=disabled -Dgst-full-elements='filesrc;matroskademux;vp8dec;xvimagesink' builddir
after I build and install gstreamer using ninja I build the program using the invocation
gcc -static -g -o test_bin_static test_bin.c $(pkg-config --cflags gstreamer-1.0) $(pkg-config --libs gstreamer-1.0) -lpcre -lffi -ldl
I receive the following warnings about the use of dlopen, presumably in functions that load plugins. It feels strange to link libdl into a static porgram, but I guess it's necessary to support the plugin architecture? However, as I understand it, since I'm including all the plugins I use in the static archive this shouldn't cause problems.
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libgmodule-2.0.a(gmodule.c.o): in function `g_module_open':
(.text+0x713): warning: Using 'dlopen' in statically linked applications requires at
runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.c.o): in function `g_get_user_database_entry':
(.text+0x277): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: (.text+0xe0): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: (.text+0x11e): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
The issue is that when I run the program the gstreamer runtime claims that the plugins are missing. Interestingly I get this error when I build dynamic programs following the install, so I think maybe the issue is in the flags I built gstreamer with. However, I'm not sure how to remedy this
(test_bin_static:1093706): GStreamer-CRITICAL **: 12:00:26.577: gst_element_set_state: assertion 'GST_IS_ELEMENT (element)' failed
(test_bin_static:1093706): GStreamer-CRITICAL **: 12:00:26.577: gst_element_get_bus:
assertion 'GST_IS_ELEMENT (element)' failed
(test_bin_static:1093706): GStreamer-CRITICAL **: 12:00:26.577: gst_bus_timed_pop_filtered: assertion 'GST_IS_BUS (bus)' failed
(test_bin_static:1093706): GStreamer-CRITICAL **: 12:00:26.577: gst_object_unref: assertion 'object != NULL' failed
error: no element "filesrc"
update: I've checked the version of gst-inspect I built and it doesn't show any of the plugins I'm trying to use, so the issue is definitely the build, but I don't know how to fix it.