2
votes

When trying to compile with Code::Blocks the example that comes up with GTK+:

#include stdlib.h
#include gtk/gtk.h

static void helloWorld (GtkWidget *wid, GtkWidget *win)
{
  GtkWidget *dialog = NULL;

  dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);
}

int main (int argc, char *argv[])
{
  GtkWidget *button = NULL;
  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;

  /* Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  /* Create the main window */
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (win), 8);
  gtk_window_set_title (GTK_WINDOW (win), "Hello World");
  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  gtk_widget_realize (win);
  g_signal_connect (win, "destroy", gtk_main_quit, NULL);

  /* Create a vertical box with buttons */
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  g_signal_connect (button, "clicked", gtk_main_quit, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}

I receive the following errors:

ld.exe||cannot find -lgobject-2.0|
ld.exe||cannot find -lglib-2.0|
||=== Build finished: 2 errors, 0 warnings ===|

I have linked both to the project, but I can't find a way to make it work. I have tried both the bundled and separated packages from http://www.gtk.org/download-windows.html. I'm pretty sure it must be something simple/stupid but I couldn't find anything that could help me to solve this problem.

2
How are you building your code? What's the command you are using?chrisaycock
Even if I have somehow worked it out by now, where can I find the full build command in Code::Blocks?Filgera
may be use make file for compiling your project?G-71

2 Answers

2
votes

Have you added the GTK Directory containing the libglib-2.0.a, libgobject-2.0.a files to the Linker Search Directories.
This can be done from the following Path:
Settings | Compiler and debugger... | Search directories | Linker | Add.

The full command line for the compiler/linker can be viewed in the Build Log window. To enable this go to:
Settings | Compiler and debugger... | Other Settings | Compiler logging | Full command line

I didn't come across the missing entrance point issue so maybe your copy of GTK is corrupted. Download the All-in-one bundle from GTK+ 2.22

make sure you add all the Include Directories in Search directories | Compiler

As a side note you may need to compile your project using -mms-bitfields which can be added in: Settings | Compiler and debugger... | Other options just paste the flag as is.

0
votes

When code::blocks is running ld.exe instead of calling it with, for example: -l glib-2.0 it is calling it with -lglib-2.0

Adding a space before the lib's name in code::block's linker options should fix it.