Build a GTK development environment in Windows

Source: Internet
Author: User

1. First install mingw (GNU Compiler Collection (GCC) for Windows). On the select components page, select C ++ compiler and msys basic system ", if you do not know how to install all the packages, select the installation directory (C:/mingw by default). The program starts to automatically download various packages and the installation is complete.

2. Set the mingw environment variable. Right-click "my computer"-> "properties"-> "advanced"-> "environment variables"-> "system variables", and modify the PATH variable value, add the mingw directory (C:/mingw/bin ). After setting, enter GCC in the command line (CMD). If GCC: no input files is displayed instead of the command not found, the mingw compilation environment has been set up successfully.

Write a "hello World" Test Program (hello. cpp, File Location D:/Hello. cpp ):
# Include <stdio. h>

Int main (INT argc, char * argv [])
{
Printf ("Hello world! ");
Return 0;
}

Enter gcc d:/Hello. C-o d:/hello in the command line (CMD) to compile.

3. To begin. Download the package and click "Install". Next, install it in the C:/mingw/msys directory. After the installation is complete, a command line window will pop up asking you
Do you wish to continue with the Post install? [YN], enter y, and press Enter.
Do you have mingw installed? [YN], enter y, and press Enter.
Please answer the following in the form of C:/Foo/bar.
Where is your mingw installation ?, Enter the mingw installation path (C:/mingw ).
4. Download all-in-one bundles(gtk0000-bundle_2.18.7-2010020._win32.zip) at http://www.gtk.org/download-windows.html and decompress the package to the C:/mingw/GTK + directory.
5. Set GTK + environment variables. Right-click "my computer"-> "properties"-> "advanced"-> "environment variables"-> "system variables", and modify the PATH variable value, add the GTK + directory (C:/mingw/GTK +/bin ). Enter PKG-config -- cflags GTK +-2.0 in the command line (CMD). If the command can be found, the compiling environment of GTK + is also set up successfully.

Verify that the installation is correct (no need to write helloworld) and run the following command on the CMD command line:
GTK-demo
If the interface is displayed, the installation is correct.

You can also write a simple GTK + Test Program (base. 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;
}

Open msys (CMD cannot be compiled) and enter gcc C:/base. c-o C:/base 'pkg-config -- cflags -- libs GTK +-2.0 '. After compilation is successful, enter C:/base, a GTK + window will pop up.

To use Microsoft's Windows theme engine, create a new file named gtkrc under the ETC/gtk-2.0 directory under the installation directory with only one sentence:
GTK-theme-name = "MS-Windows"
Save and exit.

6. GTK settings for VC Compilation

A. Add include files and include the GTK header file in VC ++ 6 menu> Tools> Options> directories. C:/mingw/GTK +/include, C: /mingw/GTK +/include/ATK-1.0, C:/mingw/GTK +/include/Cairo, C:/mingw/GTK +/include/fontconfig, C: /mingw/GTK +/include/FreeType2/FreeType/config, C:/mingw/GTK +/include/GAIL-1.0, C:/mingw/GTK +/include/glib-2.0, c:/mingw/GTK +/include/GTK-2.0, C:/mingw/GTK +/include/libpng14, C:/mingw/GTK +/include/PANGO-1.0, C: /mingw/GTK +/lib/glib-2.0/include, C:/mingw/GTK +/lib/GTK-2.0/include;

B. Add library files, VC ++ 6 menu-> Tools-> options-> directories contains the GTK library file, C:/mingw/GTK +/LIB;

C. Create a Win32 console application. CPP file, paste the code in step 1, and remove the code in the link of Project setting. add the following to the Lib file:
Glib-2.0.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gobject-2.0.lib gdk_pixbuf-2.0.lib gthread-2.0.lib gmodule-2.0.lib intl. Lib, and then compiled to run.

Note: Steps A and B will affect the entire VC environment. After one setting, all GTK code can be compiled. However, when the GTK project is transplanted to another VC compiler, You need to reset it, you can add the header file path of step a to project setting-> C/C ++-> Preprocessor/Additional include directories of each project, zaiproject setting-> link-> input/Additional library path is added to the library file path in step B.

Related Article

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.