Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: GTK and Eclipse?

  1. #1
    Join Date
    May 2008
    Beans
    16

    Question GTK and Eclipse?

    I've set up the eclipse cdt and it successfully compiled the hello world program. I'm not trying to run this simple GTK program:

    Code:
    /*
     *File name: window.c
     */
    
    #include <gtk/gtk.h>
    #include <glib.h>
    
    int main (int argc, char *argv[])
    {
      /*-- Declare the GTK Widgets used in the program --*/
      GtkWidget *window;
    
      /*--  Initialize GTK --*/
      gtk_init (&argc, &argv);
    
      /*-- Create the new window --*/
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    
      /*-- Display the window --*/
      gtk_widget_show(window);
    
      /*-- Start the GTK event loop --*/
      gtk_main();
    
      /*-- Return 0 if exit is successful --*/
      return 0;
    }
    I get the No such file or directory errors on gtk/gtk.h and glib.h includes and I'm sure it's because I don't have my Project build setting set up right. I've tried appending several extended commands to the g++ build string with no success. Anyone know how to set up the Eclipse CDT to be able to compile GTK programs? Thanks in advanced for any serious replies!

    David Cheeseman

  2. #2
    Join Date
    Feb 2007
    Location
    Heaven
    Beans
    486
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: GTK and Eclipse?

    I managed to configure NetBeans to compile GTK apps by simply guessing how to do that, doing the same with Eclipse - I failed, even after googling a bit. So I decided to stick with NetBeans and I'm very happy, if no one answers your question I suggest trying what I did.
    62°23′30″N 145°09′0″W
    ёёмаёё..

  3. #3
    Join Date
    Dec 2007
    Location
    UK
    Beans
    571
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: GTK and Eclipse?

    Are you sure that you have installed the GTK development libraries? Not having installed it would produce an error like that.

  4. #4
    Join Date
    May 2008
    Beans
    16

    Re: GTK and Eclipse?

    Quote Originally Posted by mike_g View Post
    Are you sure that you have installed the GTK development libraries? Not having installed it would produce an error like that.
    I had not installed it (thought it was pre-installed with ubuntu). However, now I have the libraries included via the Directories part of the Project Build Configurations in Project Properties but am now getting this error:

    Code:
    Severity and Description	Path	Resource	Location	Creation Time	Id
    /usr/include/glib-2.0/glib/garray.h error: ‘array’ was not declared in this scope		Test	line 94	1211840857378	1133
    And my includes are set up as follows:

    Code:
    /usr/include/gtk-2.0
    /usr/include/glib-2.0/glib
    /usr/include/c++/4.2.3
    /usr/include/glib-2.0
    I figured 'array' should've been covered by the second include. Is this the correct way to include items? Should I be using a different method? If not, why doesn't it recognize 'array' (which I believe is included via glibconfig.h).

    Thanks for your replies!

  5. #5
    Join Date
    Apr 2008
    Beans
    83

    Re: GTK and Eclipse?

    I'm having the same problem... I have gtk2.0-dev, glib2.0-dev packages installed, but I still get a cascading series of errors when compiling a simplified version of this program in Eclipse.

    Help?

    Thanks.

  6. #6
    Join Date
    Apr 2008
    Beans
    83

    Re: GTK and Eclipse?

    I did get it to compile, but I had to explicitly add all the following to my project:

    /usr/include/gtk-2.0
    /usr/lib/gtk-2.0/include
    /usr/include/glib-2.0
    /usr/lib/glib-2.0/include
    /usr/include/cairo
    /usr/include/atk-1.0
    /usr/include/pango-1.0

    which got rid of the errors. I had to add /usr/lib to my lib search path and gtk to my lib list (no surprise there).

    I thought there was supposed to be an environment variable that defined the INCLUDE path, or C_INCLUDE_PATH, or CPLUS_INCLUDE_PATH. It's not set on my system. Where should I set it, and will Eclipse respect it when it's there?

    Thanks!

  7. #7
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: GTK and Eclipse?

    Combining information from a number of sources, as long as you have the GTK source libraries installed (check in /usr/include/ for gtk-2.0), you can set up Eclipse to work with GTK files like this. This is a workaround, and I'm sure there's a better way

    * Create a new 'C Project', Project type 'Executable', toolchain 'Linux GCC', selecting defaults for all pages
    * Once the project is created, right-click on the project name and choose 'properties' (Alt-Enter)
    * Expand the C/C++ Build menu and select 'Settings'
    * In "GCC C Compiler", change the 'Command line pattern', add
    Code:
    `pkg-config --cflags --libs gtk+-2.0`
    after
    Code:
    ${COMMAND}
    Example:
    Code:
    ${COMMAND} `pkg-config --cflags --libs gtk+-2.0` ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
    * Do the same in GCC C linker

    You should now be able to build and run GTK source files from Eclipse.

    I have successfully compiled and run both tutorial files from http://library.gnome.org/devel/gtk-t...table/c39.html using the above settings.
    Last edited by cro; July 12th, 2008 at 12:10 PM. Reason: added link to GTK tutorial

  8. #8
    Join Date
    Sep 2007
    Location
    GA
    Beans
    22

    Re: GTK and Eclipse?

    In case anyone else stumbles onto this post like I did...
    Those are backticks (key above tab) not single quotes. Explanation of the compilation options here - http://library.gnome.org/devel/gtk-t...able/x111.html

  9. #9
    Join Date
    Feb 2009
    Location
    Costa del Sol, Spain
    Beans
    48
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: GTK and Eclipse?

    Here's a way to do what cro (above) has done but a little more elegantly and easier to use and remember.

    In eclipse

    window->preferences

    expand c/c++ then select Managed Build

    click on new (define a variable)

    Name: gtkc
    Value: `pkg-config --cflags --libs gtk+-2.0`
    (note backwards single quotes are important)

    click OK

    Repeat if you want to set up one for c++ as well using the c++ variables.

    click apply
    click Ok

    Now you have one or two compiler variables you can apply to any c or c++ project as shown below.

    select your project (in this case a c project) then

    project->properties

    select c/c++ Build

    under GCC C Compiler-> Miscellaneous

    in Other Flags add ${gtkc} at the end

    select GCC C Linker->Miscellaneous

    in Linker Flags add ${gtkc}

    click apply

    click OK.

    Have fun.
    Greetings

    Steve

  10. #10
    Join Date
    Jun 2007
    Location
    Universo que se expande
    Beans
    39
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Smile Re: GTK and Eclipse?

    thanks sms0611, it works perfectly!
    La gente ignorante es más feliz.

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •