Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » adding gtk-library, c++(problem include gtk-library)
adding gtk-library, c++ [message #994201] Wed, 26 December 2012 17:51 Go to next message
jackomo jack is currently offline jackomo jackFriend
Messages: 3
Registered: December 2012
Junior Member
moved from newcomers forum:

Dear Alle,

I worked on Eclipse using C. Now I want to write a little Programm for my Ubuntu Environment using C++ and GTK.

I tried a bunch of tutorial, I know, adding the gtk-libraries is not easy in eclipse, but i like the debugging environment Smile

my basic c++ code:
#include <gtk/gtk.h>

int main(int argc, char *argv[])
GtkWidget *window;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

// g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

return 0;

When I compile on the terminal using this, everything works out fine (so gtk is properly installed Smile

g++ gtkstart main.cpp $(pkg-config gtk+-2.0 --cflags --libs)

here is where the Problem starts...
First I added in Ecplipse gtk libraries to: projekt(right-click) -- properties -- C/C++ general -- paths and symbols -- GNU C++ and added:
a bunch more that came to my mind --> Result: #include <gtk/gtk.h> still unknown...
#edit: klick on apply on the richt bottom corner--> library new set up so gtk/gtk.h is known! Smile

Now I added to the compiler and Linker the libraries, that the pkg-config function gives out when I compile the cpp-file on the terminal.
pkg-config output:

-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0

just bunch of libraries

Added this under properties - c/c++ - settings - then the linker and the c++ compiler - expert mode: comand line --- and added it here at the end so that the comand line looks similar to the one that works on the terminal.

Building file: ../src/test3.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test3.d" -MT"src/test3.d" -o "src/test3.o" "../src/test3.cpp" -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0
Finished building: ../src/test3.cpp

Building target: libtest3
Invoking: GCC C++ Linker
g++ -shared -o "libtest3" ./src/main.o ./src/test3.o -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0
/usr/bin/ld: ./src/test3.o: relocation R_X86_64_PC32 against undefined symbol `gtk_init' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

the Linker has a Problem with gtk_init which should be a very basic gtk function, so actually no problem..

I added the /usr/lib/x86_64-linux-gnu/ (divided in path and library) to the linker libraries but gtk/gtk.h is still unknown.
By accident I managed that gtk/gtk.h was not a problem anymore, but I dont find it again. I think just trying is not the way anymore. Here I need your help.
What is the difference of adding libraries to this 1000 places? where to add what? I basically just want to link the gtk library.
What is the difference between compiling in eclplse and in the terminal? Works here but not on the other one?
you see, I'm in the middle of nowhere.

Using Ubuntu 12.04, Eclipse 3.7.2, C/C++ Development Tools SDK Eclipse CDT
but strangly und Help is no link to the marketplace.
should be helpful...

#little edit, gtk/gtk.h now known Smile!
Re: adding gtk-library, c++ [message #994213 is a reply to message #994201] Wed, 26 December 2012 18:48 Go to previous message
jackomo jack is currently offline jackomo jackFriend
Messages: 3
Registered: December 2012
Junior Member
Problem solved Smile!

Again, I tried to modify the Linker command line command to adapt it to

g++ gtkstart main.cpp $(pkg-config gtk+-2.0 --cflags --libs)

as close as possilbe.
Eclipse always added -shared to the command, to activate the shared library settings; I thought this might be needed, but when you go to properties - C/C++ Build - setting - GCC C++ Linker - Shard Library Settings - deactivate Shared (-shared), it Works Smile
No real clue why Smile

How to mark a thead as solved?
Previous Topic:Disabling autoformat
Next Topic:Can eclipse launch configuration file be saved in a directory outside of workspace?
Goto Forum:

Current Time: Mon Jun 18 03:19:27 GMT 2018

Powered by FUDForum. Page generated in 0.01700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top