📜 ⬆️ ⬇️

GTK + VisualStudio 2008: Quick Start

To create a cross-platform application, the well-known GTK library was chosen, but if everything is more or less simple on Unix systems (although of course, and not always sometimes), then with the installation and use on Windows systems, some questions may arise.

I would like to share the solution of these issues, or to be more precise, the setup of Microsoft Visual Studio 2008 for working with GTK libraries.

Perhaps, for people who know Visual Studio well, this information will not seem new, but for a beginner who would like to test his first “Hello World”, I think it will not be superfluous. If interested, then go ...
')


First we need the GTK library itself (I assume that Visual Studio itself is already installed;)). You can take the already compiled libraries or sources on the official website , but I chose to use the project " gladeWin32 ". We will not dwell on it for long, I will only say that this package is the Glade2 / Gtk + port on the Windows platform, and differs from the original in that specific problems have been fixed. Gtk + and libglade development packages are also installed, which is what we need. This package is notable for the fact that during the installation it analyzes the installed IDEs (including even the CygWin environment) and suggests immediately specifying the paths to the installed components and libraries. However, unfortunately, even the latest version to date (2/12/9 of 04/16/2008) did not reveal the presence of Visual Studio 2008, so you have to register with your hands;)

So, after installing the gtk-dev-2.12.9-win32-1.exe package (by default it is installed in C: \ GTK \), launch Visual Studio. Open the window with the settings “Options” (Menu-> Tools-> Options). In the tree on the left, open: Projects and Solutions-> VC ++ Directories.

Piccy.info - Free Image Hosting

In the right part, select the “Show directories for: -> Include files” selector and add the following paths here:

C:\GTK\lib\gtk-2.0\include
C:\GTK\lib\glib-2.0\include
C:\GTK\include\cairo
C:\GTK\include\libglade-2.0
C:\GTK\include\gtk-2.0
C:\GTK\include\libxml2
C:\GTK\include\pango-1.0
C:\GTK\include\glib-2.0
C:\GTK\include\atk-1.0
C:\GTK\include


Then select “Show directories for: -> Library files” in the same selector, and add two more paths:

C:\GTK\include\glib-2.0\glib\
C:\GTK\lib


Well, in principle, that's all, now to check that everything is properly configured, we will create a small “hello world”.

Select a new empty project “Visual C ++ -> Win32 -> Win32 Console Application”.

Piccy.info - Free Image Hosting

add to the project "main.cpp":

#pragma comment(lib,"gtk-win32-2.0.lib")
#pragma comment(lib,"gobject-2.0.lib")

#include <gtk/gtk.h>

int main (int argc, char *argv[]) {

GtkWidget *window;

gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);

gtk_main ();

return 0;
}


Of course, instead of #pragma, you can connect libraries directly to the project, but this is already a matter of taste, which is more convenient for me personally.

Well, this is where the setup is completed, we collect (CTRL + F5) and if everything is fine, we get such a wonderful window ...

Piccy.info - Free Image Hosting

ps I hope this information is useful to someone, and if not - do not judge strictly;)

Source: https://habr.com/ru/post/43076/


All Articles