(1) Step by Step learn the beginning of GTK +

Source: Internet
Author: User
Tags cairo gtk php download

As an old programmer, I want to learn some cross-platform open-source projects, such as GTK + and gstreamer. Close-up Blogs help me learn more, may be a lot of content is directly extracted from some tutorials, such as copyright issues, please contact me: 28341847@qq.com.

In this series, according to the content in the Chinese version of GTK + programming (PDF), extract some content or code that I think is more important, and add some personal notes and experiences, in order to achieve the purpose of learning, it will involve differences in Linux and Windows, and strive to achieve cross-platform compilation of all code.

Sample Code environment:
Windows: win7 + mingw + code: Block
Linux: centos6.3 + code: block (in virtualbox virtual machine)

1. What is GTK +?

GTK +A function library is used to help create a graphic interactive interface. The entire function library is written in C. The GTK + function library is also called the gimp toolkit. In the beginning, GTK + was used to compile the "gimp"-graphic processing software. Since then, GTK + has gradually become one of the most popular tool kits for graphic interaction interface (GUI) Design in Linux and bsdunix. Today, most GUI software (with graphic interactive interfaces) in Linux is written by GTK + or QT. GTK + is an object-oriented API (applicationprogramming interface ). Glib is the basis of GTK +, and this "Object Oriented System" is provided by "Glib.GobjectThat is, this object-oriented mechanism can bind many development languages to GTK +. Currently, the following languages are available: C ++, Python, Perl, Java, C #, PHP, and other advanced languages.
There is a dependency between GTK + and the following "function library ".
• Glib
• Pango
• ATK
• Gdk
• Gdkpixbuf
• Cairo
GlibIs a common function library. She provides a variety of language features, such as various data types, string functions, error notifications, message queues, and threads.PangoIs a function library used to implement internationalization and localization.ATKIs an approachable tool function package, which provides the shortcut key service to make it easier for people with physical defects to use their computers.GdkIt is a function library that provides some underlying "graphic implementation" and "window implementation" methods for the entire GTK + graphics library system. In Linux, gdk is located between the X server and the GTK + function library. In recent GTK + Releases, more and more functional functions are handed overCairoFunction library.GdkpixbufThe function library is a function library toolkit used to load images and maintain image "cache" (Pixel Buffer ).CairoIs a function library used to create two-dimensional images. Since GTK + 2.8, Cairo has become a member of the GTK + system. GNOME and xfce desktop environment systems are all programmed using GTK +. SWT and wxWidgets are a well-known programming framework and implemented using GTK +. The most outstanding GTK + software representatives are Firefox and inkscape.

2. Install the GTK + Development Environment

1. Installation code: Blocks
Linux: http://www.codeblocks.org/downloads/26#linux64 I downloaded for centos
Windows: http://www.codeblocks.org/downloads/26#linux64 with mingw available

2. Install GTK + (YUM installation)

Linux:

yum install gtk2 gtk2-devel gtk2-devel-docs

Windows:
Http://www.gtk.org/download/win32.php download all-in-one bundle Installation

3. Configure the code: GTK + compiler in blocks
After GTK is installed, you can use PKG-config -- list-all to view it. It should contain a GTK +-2.0.
In code: blocks, the default compiler is GNU gcc compiler. We set a separate compiler for GTK:
Settings-> compiler settings, select GNU gcc compiler, click Copy, enter the name of a GTK Compiler: Gun GCC compiler gtk2.0, set it to the default compiler, and click set as default. then, in Compiler settings-> other options-> Add 'pkg-config -- cflags GTK +-2.0 '(to add include ), in linker settings-> Other Linker Options, add PKG-config -- libs GTK +-2.0 '(to add Lib). If you run it in windows, an error may occur, if zlib1.dll is missing, place it in Project/bin/debug.

 

4. test whether the environment is correct.
Create a new project in codeblocks, select the newly added Compiler (gun gcc compiler gtk2.0), and add the code in Main. C:

#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;}

Compile and execute a blank form (executed on the command line in Linux), which indicates that the development environment of GTK + is successfully configured. By the way, you can directly use the GCC command line to generate:
Gcc-O hello-world main. c 'pkg-config -- cflags -- libs GTK +-2.0'

The following are the effects of Windows 7 and Linux (centos ).

 

 

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.