61
C - C++ / Re: Interface Programming using C's gtk libraries
« Last post by Xires on February 25, 2016, 10:07:32 pm »Structs and classes are very different things. A structure is just a contiguous spot in memory allocated such that different sections can be accessed as different variables. I can provide some examples if you need them.
As for GTK+..make sure that you have pkg-config installed(it should be, but it might not be). Once you're certain it's installed(which can be tested via "pkg-config --version") then you'll want to make sure that it can provide you with the cflags(compilation flags) and libs needed for compiling & linking your project(using "pkg-config --cflags --libs gtk+-3.0"; note there are no backquotes). Next you'll throw together a simple test program. Note that the test program need not be an elaborate example(which the documentation-provided 'hello world' is, IMHO), but rather just need something that will compile & link properly with the selected package.
If you've made it to this point successfully, then you can start working on more elaborate examples and stepping through the documentation.
Personal notes:
Honestly, I've worked with GTK quite a bit in the past and I have to warn you, it's a bit of a horrific mess. You can certainly get through it but be sure you understand the language properly. If GTK starts bringing in questions about how C works due to a specific feature or something then it's time to step back and make sure you really know C.
I love C, but I personally feel that GUI development is a better task for C++. C++ provides the necessary features to help facilitate not just OOP, but also proper event-driven design. There are also more(and some might say 'better') frameworks available with C++. GTK is still an option(with gtkmm) but you also get Qt(a FAR better framework to learn, especially if you're just starting out), wxWindows(which is also great, by comparison), and FLTK(which I like, but research it first). Of the C++-available options, I'd suggest learning Qt first as it has a large following and you'll find it more useful professionally(as in, it's worth putting on your CV).
With GTK often comes Glib, which is its own mess. It's useful in some ways and provides common data structures, but it lacks...grace. The documentation for both GTK & Glib is also lacking, in my opinion. Of course, GTK & Glib are both worth learning, eventually, but be aware that it takes some tenacity to get through.
As for GTK+..make sure that you have pkg-config installed(it should be, but it might not be). Once you're certain it's installed(which can be tested via "pkg-config --version") then you'll want to make sure that it can provide you with the cflags(compilation flags) and libs needed for compiling & linking your project(using "pkg-config --cflags --libs gtk+-3.0"; note there are no backquotes). Next you'll throw together a simple test program. Note that the test program need not be an elaborate example(which the documentation-provided 'hello world' is, IMHO), but rather just need something that will compile & link properly with the selected package.
Code: (bash) [Select]
xires@Synthesium:~/proj/code/c$ pkg-config --version
0.26
xires@Synthesium:~/proj/code/c$ pkg-config --cflags --libs gtk+-3.0
-pthread -I/usr/local/include/libpng16 -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/atk-1.0 -I/usr/include/cair
o -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/i
nclude/libpng12 -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0
xires@Synthesium:~/proj/code/c$ cat gtktst.c
Code: (c) [Select]
#include <gtk/gtk.h>
int main(int argc, char **argv) {
gtk_init(&argc, &argv);
return 0;
}
Code: (bash) [Select]
xires@Synthesium:~/proj/code/c$ gcc -Wall -Wextra -W -ansi -pedantic -o gtktst{,.c} `pkg-config --cflags --libs gtk+-3.0`
xires@Synthesium:~/proj/code/c$ ldd gtktst | grep gtk
libgtk-3.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007f8a1e107000)
xires@Synthesium:~/proj/code/c$
If you've made it to this point successfully, then you can start working on more elaborate examples and stepping through the documentation.
Personal notes:
Honestly, I've worked with GTK quite a bit in the past and I have to warn you, it's a bit of a horrific mess. You can certainly get through it but be sure you understand the language properly. If GTK starts bringing in questions about how C works due to a specific feature or something then it's time to step back and make sure you really know C.
I love C, but I personally feel that GUI development is a better task for C++. C++ provides the necessary features to help facilitate not just OOP, but also proper event-driven design. There are also more(and some might say 'better') frameworks available with C++. GTK is still an option(with gtkmm) but you also get Qt(a FAR better framework to learn, especially if you're just starting out), wxWindows(which is also great, by comparison), and FLTK(which I like, but research it first). Of the C++-available options, I'd suggest learning Qt first as it has a large following and you'll find it more useful professionally(as in, it's worth putting on your CV).
With GTK often comes Glib, which is its own mess. It's useful in some ways and provides common data structures, but it lacks...grace. The documentation for both GTK & Glib is also lacking, in my opinion. Of course, GTK & Glib are both worth learning, eventually, but be aware that it takes some tenacity to get through.