The first GTK program in Windows

Source: Internet
Author: User
Tags cairo gtk windows download
In
This article explains how to create and compile GTK under the Windows operating system. GTK uses glib, Cairo, pango, ATK, GTK +, and gettext-
Runtime, LibPNG, libjpeg, LibTIFF, and zlib. Therefore, you must also obtain these kits, which can be obtained from Windows download on the GTK official website, the simplest way is to get all-in-one bundle.

The following describes the steps for security protection:

  1. Renew minggw in http://www.mingw.org/

  2. Obtained from GTK Official Website
    All-in-One bundle
  3. Select "security base Tools", "g ++", and "make ".
  4. Deploy all-in-one bundle
  5. Add the bin path of mingw to the path of Environment Change and the bin path of GTK after the environment change.


Labels:

$ PKG-config -- cflags -- libs GTK +-2.0> inc.txt

The following commands can be used to obtain lib saved to lib.txt:

$ PKG-config -- Libs -- libs GTK +-2.0> lib.txt

After a convenient start, you can write a complete set of makefilefiles, and specify the content of inc.txt‑lib.txt to cflags and libs:

  • Makefile
CC = gcc
CFLAGS = -mms-bitfields -IC:/Winware/Gtk/include/gtk-2.0
-IC:/Winware/Gtk/lib/gtk-2.0/include -IC:/Winware/Gtk/include/atk-1.0
-IC:/Winware/Gtk/include/cairo -IC:/Winware/Gtk/include/pango-1.0
-IC:/Winware/Gtk/include/glib-2.0 -IC:/Winware/Gtk/lib/glib-2.0/include
-IC:/Winware/Gtk/include/libpng12

LIBS = -LC:/Winware/Gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0
-lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo
-lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl

main:
$(CC) foo.c -o foo.exe $(CFLAGS) $(LIBS)


Then you can create a simple GTK program:

  • Foo. 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_window_set_title (gtk_window (window), "haha! GTK +! ");
Gtk_widget_show (window );
Gtk_main ();

Return 0;
}


In order to display Chinese characters, your case must be saved as a UTF-8 (without bom at the beginning of the statement), and then begin with the make command:

$ Make
GCC Foo. C-o foo.exe-MMS-bitfields-ic:/winware/GTK/include/gtk-2.0-ic:/winwar
E/GTK/lib/gtk-2.0/include-ic:/winware/GTK/include/atk-1.0-ic:/winware/GTK/incl
Ude/Cairo-ic:/winware/GTK/include/pango-1.0-ic:/winware/GTK/include/glib-2.0-
IC:/winware/GTK/lib/glib-2.0/include-ic:/winware/GTK/include/libpng12-LC:/winw
Are/GTK/lib-lgtk-win32-2.0-lgdk-win32-2.0-latk-1.0-lgdk_pixbuf-2.0-lpangowi
N32-1.0-lgdi32-lpangocairo-1.0-lpango-1.0-lcairo-lgobject-2.0-lgmodule-2.0
-Lglib-2.0-lintl

Run the following statement to create foo.exe:

 

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.