2

I am new (relatively) to C++ and to SO.

Having stretched the creativity of console applications to the limit, my very rabid mind wants to know how to code GUIs now. I did some research, decided to use GTK rather than Qt because of having freedom of choice, there being no strings attached and something about slow internet and having to download some 0.6GB were I to go with Qt.

It has been a brutal 48 hours trying to build 'Hello World' on Gtk. This is me throwing a tantrum. I'm using Visual Studio 2010. Perhaps this is the source of all my woes. It seems Gtk is meant for C and not C++. After solving issues with header files includes and a certain notorious glibconfig.h missing (which I downloaded from the internet only to find, to my horror,that it is supposed to be a generated file), the compiler threw syntax errors,especially in one gatomic.h.

I suspect 10 errors will come up for every one I manage to solve. This is where you come in. Do you use Gtk to develop c++? If not, why so? What would you recommend instead? Do you use Gtk on windows? How is that possible? Please give details.

Is it possible to make cross-platform apps that use C++ code and a Python/VB GUI?

Your answer will be sincerely appreciated.

Mihai Maruseac
  • 20,967
  • 7
  • 57
  • 109
automaton
  • 1,091
  • 1
  • 9
  • 23

2 Answers2

3

First off, a general note: Gtk being mainly developed as a toolkit for Gnome, I think it is fair to say that the main focus is high quality on Linux while other platforms are somewhat second-class citizens. This is probably most visible by looking at the integration with the native look and feel of Windows and MacOS. If you are looking for a toolkit which behaves equally well on all major platforms, I'd recommend you reconsidered Qt.

As far as your more specific questions are concerned:

C/C++

Gtk is written in C, and consequently has a C API. If you are looking for a C++ API, look at the Gtkmm bindings. Note that you can also use the C API in a C++ application.

glibconfig.h

I don't know whether you tried compiling Gtk yourself, but the easiest way to get Gtk3 for windows is by downloading the precompiled all-in-one bundle from http://www.gtk.org/download/win32.php (which includes the glibconfig.h you are missing).

When and how to use Gtk and with what language

As pointed out above, the primary users oft Gtk are people who develop applications for the Gnome desktop environment. Most cross-platform applications nowadays however use Qt since the quality on Windows and MacOS is higher compared to Gtk on those platforms.

Concerning what langauge to use, a strength of Gtk is that there exists bindings for many languages (including C++ and Python), so you are certainly not confined to C.

When developing with C++, something that I personally like about Gtkmm is that it uses the standard library, as opposed to Qt which has it's own implementations for data structures etc (the reason being that Qt predates the times when the STL was generally available and usable on all main platforms).

How to use Gtk: contrary to Qt which has the excellent Qt Creator, Gtk is somewhat lacking a specifically designed IDE for easy development. The closes you'll get is using Glade for interface design and a text editor or IDE of your choice for the coding, but that choice will differ depending on the platform you are on. Clearly, as you probably noticed, integrating Gtk into the environment of choice usually requires some work (and also some more technical knowledge). So again, if you are looking for an easy to set-up and use environment for developing GUI applications, I'd just go with Qt and Qt Creator.

Cross-Platform apps

First off, Visual Basic is not cross-platform. But generally speaking, there are plenty of possibilities for doing cross-application development, using various languages.

smani
  • 1,953
  • 17
  • 13
0

I've had to get a gtk3 project working on windows a few months ago, when gtk3 just came out for windows. I've had problems compiling it under Visual Studio as well, and posted a question here, specifically this one.

Here's how I got it working on windows:

  1. Download the all-in-one bundle for Windows from gtk.org
  2. Install, etc, set up include/link dirs within the project. (personally, I dumped gtk's folders in the project folder, pointed at "include" as an include dir and "lib" as a link dir, then proceeded to move any files/folders the compiler cannot find around to the root of "include" )
  3. If not set up automatically, add include and link dirs as necessary until the compiler finds all the files.
  4. If using MinGW to compile, it will succeed at that point.
  5. If using Visual Studio, you have to modify gtk headers as described in the gtk mailing list:

    In gutils.h lines 82 and 122, and in gstring.h line 129, change "static inline" to "static __inline". Blockquote Note that the modification does not impact MinGW's ability to compile.

I have successfully compiled my gtk3 project on both windows (with either Visual Studio or Code::Blocks) and linux without writing platform-specific code that way. Just don't forget to include the required runtime dlls with the program when you ship it.

Community
  • 1
  • 1
Antonio
  • 155
  • 12