2

I have written a C program to display memory-mapped video files using GStreamer and GTK windows. The intent is to build a shared library with CFFI that I can call from Python. When I try to import the library, I get a message reporting an undefined symbol.

I recreated the problem with a library containing a small program that just displays a window:

#include <gtk/gtk.h>
#include "test_cdef.h"

int main (int argc, char *argv[])
{
  return test();
}

int test()
{
  GtkWidget  *main_window;
  gtk_init (NULL, NULL);
  main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(main_window), "Test");
  gtk_window_set_default_size(GTK_WINDOW(main_window), 1600, 900);
  gtk_widget_show_all(main_window);
  g_main_loop_run (g_main_loop_new (NULL, TRUE));
  return 0;
}

When I try to import the library, I get the following message:

ImportError: [library file name]: undefined symbol: gtk_window_get_type

After a lot of searching, the problems that seem closest to mine were fixed by changing compiler/linking options. I used gcc to build the program. I assume CFFI uses the same to build the library.

If these options should be changed, I would have two questions: (1) what options should be used, and (2) how are these options communicated to CFFI? I would appreciate help with either question.

My OS is Linux Mint 19.3. The other packages are GTK-3.0, python 3.6.9, python3-cffi 1.11.5-1.

Any help would be appreciated.

1 Answer 1

1

I found a solution. It was indeed a linking problem at two different levels -- links to build a static library and links to build the shared library that linked to the static library.

The breakthrough for me came when I was finally able to find the name of the GTK library defining the first reported symbol problem. I added that library name to the gcc link portion of the command in my makefile. With that one addition, the linker was good enough to report another missing library by name -- although the error message is a bit cryptic -- calling it a missing DSO (Dynamic Shared Object). Why the designers did not write the linker to report the omission and automatically add the missing library is a topic for another day. Adding missing libraries one-by-one, I was eventually able to build a static library without errors.

With CFFI, the missing libraries are specified in a [libraries] list and their common directory (/usr/lib/x86_64-linix-gnu on my system) is specified in a [library-dirs] list. The build of the shared library encountered a few more missing libraries, which I eventually found by searching for library files that contained text strings of the missing symbols.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.