Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » adding gtk-library, c++(problem include gtk-library)
adding gtk-library, c++ [message #994099] Wed, 26 December 2012 11:39 Go to next message
jackomo jack is currently offline jackomo jackFriend
Messages: 3
Registered: December 2012
Junior Member
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:
Quote:
#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);

gtk_widget_show_all(window);
gtk_main();
return 0;
}


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

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:
/usr/include/gtk-2.0
...gtk-3.0
...gtk-3.0/gtk
/usr/lib/glib-2.0/include
...
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:
Quote:

-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.

Quote:
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/libglib-2.0.so (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 8.0.2.201202111925 org.eclipse.cdt.sdk.feature.group Eclipse CDT
but strangly und Help is no link to the marketplace.
...findbestopensource.com/product/pkg-config-support-for-eclipse-cdt
should be helpful...


#little edit, gtk/gtk.h now known Smile!

[Updated on: Wed, 26 December 2012 14:11]

Report message to a moderator

Re: adding gtk-library, c++ [message #994197 is a reply to message #994099] Wed, 26 December 2012 17:34 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 12/26/2012 06:58 AM, jackomo jack wrote:
> 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 :)
>
> my basic c++ code:
> Quote:
>> #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);
>>
>> gtk_widget_show_all(window);
>> gtk_main();
>> return 0;
>> }
>
>
> When I compile on the terminal using this, everything works out fine (so
> gtk is properly installed :)
> Quote:
>> 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:
> /usr/include/gtk-2.0
> ..gtk-3.0
> ..gtk-3.0/gtk
> /usr/lib/glib-2.0/include
> ..
> a bunch more that came to my mind --> Result: #include <gtk/gtk.h> still
> unknown...
>
> 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:
> Quote:
>> -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.
>
> Quote:
>> 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
>
>
> Result: gtk/gtk.h still unknown but the Compiler runs through -- 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/libglib-2.0.so (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
> 8.0.2.201202111925 org.eclipse.cdt.sdk.feature.group Eclipse CDT
> but strangly und Help is no link to the marketplace.
> ..findbestopensource.com/product/pkg-config-support-for-eclipse-cdt
> should be helpful...

Wrong forum. Use the Eclipse CDT forum.
Previous Topic:Emulsifier
Next Topic:Installing EGit in Helios w/PHP development env
Goto Forum:
  


Current Time: Thu Apr 18 11:41:52 GMT 2024

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

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

Back to the top