Results 1 to 4 of 4

Thread: linker errors when compiling a simple gtk2 program

  1. #1
    Join Date
    Feb 2005
    Beans
    151

    linker errors when compiling a simple gtk2 program

    Hello.

    I use Ubuntu 11.10 x86-64 and tried to compile a simple Gtk+ 2.0 program using:
    Code:
    gcc `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0` main.c -o main
    The program is:

    Code:
    #include <gtk/gtk.h>
    #include <glib.h>
    
    int main(int argc, char **argv)
    {
    	GtkWidget *window;
    	g_thread_init(NULL);
    	gtk_init(&argc, &argv);
    
    	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    	gtk_widget_show_all(window);
    	gtk_main();
    	return 0;
    }
    But still, I get the following errors:

    Code:
    main.o: In function `g_once_init_enter':
    /usr/include/glib-2.0/glib/gthread.h:350: undefined reference to `g_once_init_enter_impl'
    The development packages for Gtk+ are installed. Please help, the same program compiles and links on other systems.

  2. #2
    Join Date
    Feb 2005
    Beans
    151

    Re: linker errors when compiling a simple gtk2 program

    Solved, the system had three gcc versions. After choosing the oldest one (4.4), it compiled and linked w/o errors.

  3. #3
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,292
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: linker errors when compiling a simple gtk2 program

    The correct command is

    Code:
    gcc -o main main.c `pkg-config --libs --cflags gtk+-2.0 glib-2.0 gthread-2.0`

  4. #4
    Join Date
    Nov 2008
    Beans
    9,635
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: linker errors when compiling a simple gtk2 program

    11.10 has the new toolchain. The new syntax has the libraries at the end. Presumably why the oldest version still worked. I believe the other distros are also going to the new toolchain shortly.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •