First, Introduction
Although GTK + is a development environment under Linux because of its cross-platform features, it is sometimes needed on windows. The following is the development environment for configuring GTK + under WINDOWS10.
GNOME's development infrastructure is built around a set of libraries, all of which are written in the portable ANSI C language and can be used on all UNIX-like systems, and the graph-related libraries depend on the X Window System. The Gnome library is the highest level. GTK + is made up of two parts, GTK and GdK. The GTK layer provides an object model for the C language and provides the most basic widget for the UI toolkit, which is the basis for the upper-level GUI derivation. GTK is dependent on GDK, GDK is an underlying wrapper for Xlib, and the Xlib library talks directly to the X server. Any part other than Xlib is based on glib, a useful library of C functions that provides a number of utilities and portable features, as well as a set of containers that are easy to use in the C language.
A GNOME program uses a hierarchy of multiple libraries: The GNOME library is at the top level, including help routines, classes, and special widgets, and provides an infrastructure for the application. The second tier is GTK, which is part of the GTK + library. This library provides basic toolkits and widgets to create GUI applications. Most of the GUI is written directly in GTK. GTK also provides a powerful object system for the GNOME library. The next layer is GDK, which simply wraps the X library, which is used only when we are doing special painting or setting the special properties of the window. The bottom layer is glib, which is a utility library for C, which includes portability and some utility functions, as well as some container classes such as: Linked list, variable group, variable length string, HASH (seemingly Hassi), cache, an event loop and other useful structures.
Second, detailed 1, download GTK + 3.x
(1) Enter GTK + 's official website http://www.gtk.org/, click Download, select the appropriate version to enter.
(2) To download, unzip, organize those individual files, it is not very convenient, so you can choose to have "all-in-one bundles" link, click to download.
Unzip complete, copy to/ETC/GTK (also can customize other directory), can see some directory folder, mainly include: Bin, etc, include, lib, man, manifest, share, SRC. Where the bin directory contains a number of executable files and dynamic link library, the Lib directory mainly contains some library files, include mainly contains some header files.
Note: MSYS2 (Minimal SYStem 2) can be installed recently under Windows, which is a standalone version of Msys, primarily for the shell command-line development environment, and it is also a Cygwin (POSIX compatibility layer) and mingw-w64 (from " mingw-generation ") is based on the pursuit of better interoperability of Windows software. It integrates the Cygwin upgrade version of Pacman and MINGW-W64, providing Linux environments such as bash shell, version control software (GIT/HG), and Mingw-w64 toolchain. The biggest difference with Msys is the porting of the Arch Linux package Management system Pacman (in fact, the difference from Cygwin). Reference: https://msys2.github.io/.
2. Configuring GTK
There is a Help file under the/ETC/GTK directory:
[HTML]View PlainCopy
- This is a bundle containing the GTK + stack and its dependencies
- For Windows. As such it's nothing more than a combination of the
- Individual packages it consists of. Here is a shortened list:
- -GTK + 3.6.4 (patched);
- -GLib 2.34.3;
- -Gdk-pixbuf 2.26.5;
- -Pixman 0.26.0;
- -Cairo 1.10.2 (patched);
- -Pango 1.30.1;
- -ATK 2.6.0.
- Both Run-time and developer packages are included.
- This bundle was intended for software developers and packagers. You are
- Expected to know how to does with it, more or less.
- To use the IT, create some empty folder like "C:\gtk", Using either
- Windows Explorer ' s built-in zip file management, or the command-line
- Unzip.exe, available for instance at
- Ftp://tug.ctan.org/tex-archive/tools/zip/info-zip/WIN32/unz552xN.exe
- Unzip this bundle. Avoid winzip! It's known to behave oddly.
- Presumably already did extract the files, as is reading
- This file.)
- Then add the Bin folder to your PATH. Make sure you has no other
- Versions of GTK + in PATH. Run:
- Pkg-config--cflags gtk+-3.0
- and verify that it prints out something reasonable. Prepare Pango:
- Pango-querymodules > C:\gtk\etc\pango\pango.modules
- Prepare Gdk-pixbuf:
- Gdk-pixbuf-query-loaders > C:\gtk\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
- Prepare Gtk+-immodules:
- gtk-query-immodules-3.0 > C:\gtk\lib\gtk-3.0\3.0.0\immodules.cache
- Run:
- Gtk3-demo
- and verify that it works.
(1) Configuring environment variables
Right-Start menu-Select Control Panel, switch to small icon or large icon mode select "System", click "Advanced System Settings", select "Environment variable", add "C:\gtk\bin" to environment variable "Path". The bin directory contains the DLL files required by the runtime, which also includes the Gtk-demo.exe sample program.
(2) Then follow the example of Pango-querymodules, Gdk-pixbuf-query-loaders, gtk-query-immodules-3.0, and then run GTK + with the Help documentation:
3, set up the Qtcreator environment (1) first install the good Qtcreator (specific reference online tutorial). (2) Create a new empty QT project and add CPP files main.cpp
[HTML]View PlainCopy
- #include <gtk/gtk.h>
- int main (int argc, char *argv[])
- {
- Gtkwidget *window;
- Gtkwidget *label;
- Initializing the GTK + library
- Gtk_init (&ARGC, &ARGV);
- Creating the main window
- window = gtk_window_new (gtk_window_toplevel);
- Set Window size
- Gtk_widget_set_size_request (window,300,300);
- Set Title
- Gtk_window_set_title (Gtk_window (window), "Hello World");
- Stop the main GTK + loop when the window is about to be destroyed
- G_signal_connect (window, "Destroy", G_callback (Gtk_main_quit), NULL);
- Create a "Hello World" label
- label = gtk_label_new ("Hello, World");
- Add a label to the main window
- Gtk_container_add (Gtk_container (window), label);
- All elements in the Settings window are visible
- Gtk_widget_show_all (window);
- Start the main loop and let it rest there until the application shuts down
- Gtk_main ();
- return 0;
- }
(3) Add GTK header file and library (pro file) Execute command in cmd pkg-config--cflags gtk+-3.0 Add to Includepath, execute command pkg-config--cflags--libs gtk+-3.0 Add Into the Libs. Of course, you can also use the simpler way: In the pro file, add:
[HTML]View PlainCopy
- CONFIG + = Link_pkgconfig
- Pkgconfig + = gtk+-3.0
The final pro file is:
[HTML]View PlainCopy
- #-------------------------------------------------
- #
- # Project created by Qtcreator 2015-08-30t02:36:02
- #
- #-------------------------------------------------
- TARGET = HelloWorld
- TEMPLATE = App
- CONFIG + = Link_pkgconfig
- Pkgconfig + = gtk+-3.0
- #INCLUDEPATH + = c:/gtk/include/gtk-3.0 C:/gtk/include/cairo c:/gtk/include/pango-1.0 \
- # c:/gtk/include/atk-1.0 C:/gtk/include/cairo c:/gtk/include/pixman-1 \
- # c:/gtk/include c:/gtk/include/freetype2 c:/gtk/include c:/gtk/include/libpng15 \
- # c:/gtk/include/gdk-pixbuf-2.0 C:/gtk/include/libpng15 c:/gtk/include/glib-2.0 \
- # C:/gtk/lib/glib-2.0/include
- #LIBS + =-lc:/gtk/lib-lgtk-3-lgdk-3-lgdi32-limm32-lshell32-lole32-wl,-luuid-lpangocairo-1.0 \
- #-lpangoft2-1.0-lfreetype-lfontconfig-lpangowin32-1.0-lgdi32-lpango-1.0-lm-latk-1.0 \
- #-lcairo-gobject-lcairo-lgdk_pixbuf-2.0-lgio-2.0-lgobject-2.0-lglib-2.0-lintl
- SOURCES + = Main.cpp
- HEADERS + =
Main.cpp's Code:
[HTML]View PlainCopy
- #include <gtk/gtk.h>
- int main (int argc, char *argv[])
- {
- Gtkwidget *window;
- Gtkwidget *label;
- Initializing the GTK + library
- Gtk_init (&ARGC, &ARGV);
- Creating the main window
- window = gtk_window_new (gtk_window_toplevel);
- Set Window size
- Gtk_widget_set_size_request (window,300,300);
- Set Title
- Gtk_window_set_title (Gtk_window (window), "Hello World");
- Stop the main GTK + loop when the window is about to be destroyed
- G_signal_connect (window, "Destroy", G_callback (Gtk_main_quit), NULL);
- Create a "Hello World" label
- label = gtk_label_new ("Hello, World");
- Add a label to the main window
- Gtk_container_add (Gtk_container (window), label);
- All elements in the Settings window are visible
- Gtk_widget_show_all (window);
- Start the main loop and let it rest there until the application shuts down
- Gtk_main ();
- return 0;
- }
4, run sometimes a startup error: "Unable to locate the program input point gzdirect in the dynamic link library Zlib1.dll. The reason: Installing some software at the time of installation will put Zlib1.dll into the C:\Windows\System32 folder, so that there is an older version of Zlib1.dll in the directory, although GTK + The bin file in the installation directory comes with Zlib1.dll, but it takes precedence to find the DLL file in the System32 folder, and this old version of Zlib1.dll causes GTK + startup errors.
Workaround: (1) C:\Windows\System32 in the Zlib1.dll rename Zlib1.dll.off or zlib1.dll.old any name, or directly delete, and then start GTK + can be opened normally. However, this method may cause other programs not to start properly. (2) Copy the Zlib1.dll in the C:\gtk\bin folder to C:\Windows\System32, and then start GTK + to open normally. The new version of Zlib can also guarantee the normal startup of the previous program. Run the result diagram:
Iii. Summary
(1) 3.6.5 and its latest version can be found on the Internet http://developer.gnome.org/gtk3/. If you are looking for the old GTK + 2 series tape library, see http://developer.gnome.org/gtk2/.
(2) If there are suggestions, please leave a message, thank you first!
http://blog.csdn.net/taiyang1987912/article/details/48103049
GTK + A brief talk on one Windows10 under Qtcreator GTK + Environment building (more than 10 articles)