Eclipse with GTK [message #1713394] |
Tue, 03 November 2015 18:38 |
Thomas Gstir Messages: 1 Registered: November 2015 |
Junior Member |
|
|
I'm fairly new to programming and just started doing some C-programming with "Eclipse". Now I'd really like to build some GUIs and after some websearch I found GTK and installed it from the website. My problem now is to get a simple code running. Eclipse tells me "Nothing to build for my_project". This is the code I'm trying to run:
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
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;
}
|
|
|
Re: Eclipse with GTK [message #1713411 is a reply to message #1713394] |
Tue, 03 November 2015 21:08 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
How did you make the Eclipse project? I started with an Hello World example and began modifying it.
In just Eclipse alone you must add paths to the GTK version you are linking (e.g., /usr/include/gtk-3.0) and the glib (e.g., /usr/includes/glib-2.0) in Project ==> Properties ==> C/C++ General ==> Preprocessor Include Paths, Macros, etc. As far as I know, nothing will do this for you. Then you will need to include not only gtk/gtk.h but glib.h and gio/gioenums.h as well. The last is merely to get the definition of G_APPLICATION_FLAGS_NONE;
After that, you're going to discover it wants glibconfig.h which is in /usr/lib64/glib-2.0/include in my installation.
Using GTK is not a simple thing. For example, there are a long list of dependencies that have to be added at both compile and link time. Using pkgconfig is perhaps the easiest (http://ubuntuforums.org/showthread.php?t=1928611)
and to do this you will need to modify the compile command
Most people use autotools to build a makefile that will compile and link the app. Discussion of this is OT for this forum.
If you are a beginner, you've a large learning curve to climb. A bit like learning to swim in shark-infested waters while carrying a concrete block.
However, there are several places you can look at:
https://villavu.com/forum/showthread.php?t=85880
https://coffeeorientedprogramming.wordpress.com/2014/09/23/hello-world-gtk3-program-in-eclipse/
Google: GTK and Eclipse
|
|
|
Re: Eclipse with GTK [message #1713480 is a reply to message #1713411] |
Wed, 04 November 2015 12:51 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
You are going to find that the pkg-config plug-in mentioned in some of the links I posted is unavailable. If it's any help, you can make build variables which will hold the results of pkg-config. For example, in my installation:
# pkg-config --cflags gtk+-3.0
yields
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libpng16
in Project ==> C/C++ Build ==> Build Variables , add a variable GTKINCS (or whatever) and set its value to the pkg-config output using cut and paste.
Similarly, with
# pkg-config --libs gtk+-3.0
-lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
add a variable GTKLIBS with the pkg-config --libs output as the value.
In Project ==> C/C++ Build ==>Settings add ${GTKINCS} to the GCC C Compiler command and add ${GTKLIBS} to the linker command.
You could use gtk+-2.0 instead of gtk+-3.0 depending on what you want.
You will still need to manually add the includes to Project ==> Properties ==> C/C++ General ==> Preprocessor Include Paths, Macros, etc. Bit of a pain but you only need to do it once. If you make a new project you can export then import the settings. Just a word of caution: run pkg-config on your installation. My installation settings may not work for you.
HTH
|
|
|
Powered by
FUDForum. Page generated in 0.02963 seconds