GTK + A brief talk on one Windows10 under Qtcreator GTK + Environment building (more than 10 articles)

Source: Internet
Author: User
Tags cairo gtk arch linux

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
  1. This is a bundle containing the GTK + stack and its dependencies
  2. For Windows. As such it's nothing more than a combination of the
  3. Individual packages it consists of. Here is a shortened list:
  4. -GTK + 3.6.4 (patched);
  5. -GLib 2.34.3;
  6. -Gdk-pixbuf 2.26.5;
  7. -Pixman 0.26.0;
  8. -Cairo 1.10.2 (patched);
  9. -Pango 1.30.1;
  10. -ATK 2.6.0.
  11. Both Run-time and developer packages are included.
  12. This bundle was intended for software developers and packagers. You are
  13. Expected to know how to does with it, more or less.
  14. To use the IT, create some empty folder like "C:\gtk", Using either
  15. Windows Explorer ' s built-in zip file management, or the command-line
  16. Unzip.exe, available for instance at
  17. Ftp://tug.ctan.org/tex-archive/tools/zip/info-zip/WIN32/unz552xN.exe
  18. Unzip this bundle. Avoid winzip! It's known to behave oddly.
  19. Presumably already did extract the files, as is reading
  20. This file.)
  21. Then add the Bin folder to your PATH. Make sure you has no other
  22. Versions of GTK + in PATH. Run:
  23. Pkg-config--cflags gtk+-3.0
  24. and verify that it prints out something reasonable. Prepare Pango:
  25. Pango-querymodules > C:\gtk\etc\pango\pango.modules
  26. Prepare Gdk-pixbuf:
  27. Gdk-pixbuf-query-loaders > C:\gtk\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
  28. Prepare Gtk+-immodules:
  29. gtk-query-immodules-3.0 > C:\gtk\lib\gtk-3.0\3.0.0\immodules.cache
  30. Run:
  31. Gtk3-demo
  32. 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
  1. #include <gtk/gtk.h>
  2. int main (int argc, char *argv[])
  3. {
  4. Gtkwidget *window;
  5. Gtkwidget *label;
  6. Initializing the GTK + library
  7. Gtk_init (&ARGC, &ARGV);
  8. Creating the main window
  9. window = gtk_window_new (gtk_window_toplevel);
  10. Set Window size
  11. Gtk_widget_set_size_request (window,300,300);
  12. Set Title
  13. Gtk_window_set_title (Gtk_window (window), "Hello World");
  14. Stop the main GTK + loop when the window is about to be destroyed
  15. G_signal_connect (window, "Destroy", G_callback (Gtk_main_quit), NULL);
  16. Create a "Hello World" label
  17. label = gtk_label_new ("Hello, World");
  18. Add a label to the main window
  19. Gtk_container_add (Gtk_container (window), label);
  20. All elements in the Settings window are visible
  21. Gtk_widget_show_all (window);
  22. Start the main loop and let it rest there until the application shuts down
  23. Gtk_main ();
  24. return 0;
  25. }
(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
    1. CONFIG + = Link_pkgconfig
    2. Pkgconfig + = gtk+-3.0
The final pro file is: [HTML]View PlainCopy
  1. #-------------------------------------------------
  2. #
  3. # Project created by Qtcreator 2015-08-30t02:36:02
  4. #
  5. #-------------------------------------------------
  6. TARGET = HelloWorld
  7. TEMPLATE = App
  8. CONFIG + = Link_pkgconfig
  9. Pkgconfig + = gtk+-3.0
  10. #INCLUDEPATH + = c:/gtk/include/gtk-3.0 C:/gtk/include/cairo c:/gtk/include/pango-1.0 \
  11. # c:/gtk/include/atk-1.0 C:/gtk/include/cairo c:/gtk/include/pixman-1 \
  12. # c:/gtk/include c:/gtk/include/freetype2 c:/gtk/include c:/gtk/include/libpng15 \
  13. # c:/gtk/include/gdk-pixbuf-2.0 C:/gtk/include/libpng15 c:/gtk/include/glib-2.0 \
  14. # C:/gtk/lib/glib-2.0/include
  15. #LIBS + =-lc:/gtk/lib-lgtk-3-lgdk-3-lgdi32-limm32-lshell32-lole32-wl,-luuid-lpangocairo-1.0 \
  16. #-lpangoft2-1.0-lfreetype-lfontconfig-lpangowin32-1.0-lgdi32-lpango-1.0-lm-latk-1.0 \
  17. #-lcairo-gobject-lcairo-lgdk_pixbuf-2.0-lgio-2.0-lgobject-2.0-lglib-2.0-lintl
  18. SOURCES + = Main.cpp
  19. HEADERS + =
Main.cpp's Code: [HTML]View PlainCopy
  1. #include <gtk/gtk.h>
  2. int main (int argc, char *argv[])
  3. {
  4. Gtkwidget *window;
  5. Gtkwidget *label;
  6. Initializing the GTK + library
  7. Gtk_init (&ARGC, &ARGV);
  8. Creating the main window
  9. window = gtk_window_new (gtk_window_toplevel);
  10. Set Window size
  11. Gtk_widget_set_size_request (window,300,300);
  12. Set Title
  13. Gtk_window_set_title (Gtk_window (window), "Hello World");
  14. Stop the main GTK + loop when the window is about to be destroyed
  15. G_signal_connect (window, "Destroy", G_callback (Gtk_main_quit), NULL);
  16. Create a "Hello World" label
  17. label = gtk_label_new ("Hello, World");
  18. Add a label to the main window
  19. Gtk_container_add (Gtk_container (window), label);
  20. All elements in the Settings window are visible
  21. Gtk_widget_show_all (window);
  22. Start the main loop and let it rest there until the application shuts down
  23. Gtk_main ();
  24. return 0;
  25. }
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.