Metalcoder
Metalcoder

Reputation: 2262

GTK Hello World complains about undefined references

I'm using Linux Mint 20 to learn GTK. I installed the following package to get started:

sudo apt-get install build-essential libgtk-3-dev

And then proceeded to compile the Hello World app in C:

#include <gtk/gtk.h>

static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *button_box;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  button = gtk_button_new_with_label ("Hello World");
  g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_close), window);
  gtk_container_add (GTK_CONTAINER (button_box), button);

  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

As the example requests, I compiled it using:

gcc `pkg-config --cflags gtk+-3.0` -o hello-world-gtk hello-world-gtk.c `pkg-config --libs gtk+-3.0`

But it didn't work, and I have no idea why. It's output was:

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_void@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_call@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_uint32@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_sint32@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_prep_cif@LIBFFI_BASE_7.0"
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libwayland-client.so.0: referência não definida para "ffi_type_pointer@LIBFFI_BASE_7.0"
collect2: error: ld returned 1 exit status

The "referência não definida para" is Portuguese to something like "undefined reference for".

Anyone knows what I need to do?

Upvotes: 1

Views: 618

Answers (1)

Metalcoder
Metalcoder

Reputation: 2262

I've managed it! The thing is, for some reason my system missed libffi. I downloaded it's latest version, and just installed it:

./configure
(...)
make
(...)
sudo make install
(...)

I've compiled it, and it worked!

Upvotes: 1

Related Questions