Ubuntu12.04安装GTK 界面设计

来源:互联网 发布:深度linux硬盘怎么分区 编辑:程序博客网 时间:2024/06/01 10:03

http://www.gtk.org/download/linux.php

Download for GNU/Linux and Unix

Requirements

You will need to get the GLib, Pango, Gdk-Pixbuf, ATK and GTK+ packages to build GTK+.
You may also need some of the external dependencies that are also linked for each version listed below.

Stable Release

To build GTK+ 3.8, see the installation guide. For additional help, the FAQ is a good starting point.

  • GTK+ 3.8
  • GLib 2.36
  • Pango 1.34
  • Gdk-Pixbuf 2.28
  • ATK 2.8

Older Versions

Some applications still require GTK+ 2, an older stable version of GTK+. You can have the run-time and development environments for GTK+ 3.x, GTK+ 2.x and GTK+ 1.2 installed simultaneously on your computer.

VersionPackagesGTK+ 3.6SourcesGTK+ 3.4SourcesGTK+ 3.2SourcesGTK+ 3.0SourcesGTK+ 2.24SourcesGTK+ 2.20SourcesGTK+ 2.18SourcesGTK+ 2.16SourcesGTK+ 2.14SourcesGTK+ 2.12SourcesGTK+ 2.10SourcesGTK+ 2.8SourcesGTK+ 2.6SourcesGTK+ 2.4SourcesGTK+ 1.2Sources

**********************************************




一、安装

  1、安装gcc/g++/gdb/make 等基本编程工具

复制代码
$sudo apt-get install build-essential
复制代码

  2、安装 libgtk2.0-dev libglib2.0-dev 等开发相关的库文件

复制代码
$sudo apt-get install gnome-core-devel 
复制代码

  3、用于在编译GTK程序时自动找出头文件及库文件位置  

复制代码
$sudo apt-get install pkg-config
复制代码

  4、安装 devhelp GTK文档查看程序

复制代码
$sudo apt-get install devhelp
复制代码

  5、安装 gtk/glib 的API参考手册及其它帮助文档

复制代码
$sudo apt-get install libglib2.0-doc libgtk2.0-doc
复制代码

  6、安装基于GTK的界面GTK是开发Gnome窗口的c/c++语言图形库 

复制代码
$sudo apt-get install glade libglade2-dev
或者
$sudo apt-get install glade-gnome glade-common glade-doc
复制代码

  7、安装gtk2.0 或者 将gtk+2.0所需的所有文件统通下载安装完毕

复制代码
$sudo apt-get install libgtk2.0-dev
或者
$sudo apt-get install libgtk2.0*
复制代码

  

二、查看GTK库版本

  1、查看1.2.x版本

复制代码
$pkg-config --modversion gtk+
复制代码

  2、查看 2.x 版本

复制代码
$pkg-config --modversion gtk+-2.0
复制代码

  3、查看pkg-config的版本

复制代码
$pkg-config --version
复制代码

  4、查看是否安装了gtk

复制代码
$pkg-config --list-all grep gtk
复制代码

  

三、测试程序

复制代码
//Helloworld.c
#include <gtk/gtk.h>int main(int argc,char *argv[]){    GtkWidget    *window;    GtkWidget    *label;        gtk_init(&argc,&argv);        /* create the main, top level, window */    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);        /* give it the title */    gtk_window_set_title(GTK_WINDOW(window),"Hello World");        /* connect the destroy signal of the window to gtk_main_quit     * when the window is about to be destroyed we get a notification and     * stop the main GTK+ loop     */    g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);        /* create the "Hello, World" label */    label = gtk_label_new("Hello, World");        /* and insert it into the main window */    gtk_container_add(GTK_CONTAINER(window),label);        /* make sure that everything, window and label, are visible */    gtk_widget_show_all(window);        /* start the main loop, and let it rest until the application is closed */    gtk_main();        return 0;} 
复制代码

  

四、编译运行

  1、编译

复制代码
$gcc -o Helloworld Helloworld.c `pkg-config --cflags --libs gtk+-2.0`
复制代码

  2、运行

复制代码
$./Helloworld
复制代码
*****************************************************************************

Compiling the GTK+ libraries

Compiling the GTK+ Libraries — How to compile GTK+ itself

 

Building GTK+ on UNIX-like systems

This chapter covers building and installing GTK+ on UNIX and UNIX-like systems such as Linux. Compiling GTK+ on Microsoft Windows is different in detail and somewhat more difficult to get going since the necessary tools aren't included with the operating system.

Before we get into the details of how to compile GTK+, we should mention that in many cases, binary packages of GTK+ prebuilt for your operating system will be available, either from your operating system vendor or from independent sources. If such a set of packages is available, installing it will get you programming with GTK+ much faster than building it yourself. In fact, you may well already have GTK+ installed on your system already.

On UNIX-like systems GTK+ uses the standard GNU build system, using autoconf for package configuration and resolving portability issues, automake for building makefiles that comply with the GNU Coding Standards, andlibtool for building shared libraries on multiple platforms.

If you are building GTK+ from the distributed source packages, then you won't need these tools installed; the necessary pieces of the tools are already included in the source packages. But it's useful to know a bit about how packages that use these tools work. A source package is distributed as a tar.bz2 ortar.xz file which you unpack into a directory full of the source files as follows:

      tar xvfj gtk+-3.2.0.tar.bz2      tar xvfJ gtk+-3.2.0.tar.xz    

In the toplevel directory that is created, there will be a shell script calledconfigure which you then run to take the template makefiles calledMakefile.in in the package and create makefiles customized for your operating system. Theconfigure script can be passed various command line arguments to determine how the package is built and installed. The most commonly useful argument is the--prefix argument which determines where the package is installed. To install a package in/opt/gtk you would run configure as:

      ./configure --prefix=/opt/gtk    

A full list of options can be found by running configure with the--help argument. In general, the defaults are right and should be trusted. After you've runconfigure, you then run the make command to build the package and install it.

      make      make install    

If you don't have permission to write to the directory you are installing in, you may have to change to root temporarily before runningmake install. Also, if you are installing in a system directory, on some systems (such as Linux), you will need to runldconfig after make install so that the newly installed libraries will be found.

Several environment variables are useful to pass to set before running configure.CPPFLAGS contains options to pass to the C compiler, and is used to tell the compiler where to look for include files. TheLDFLAGS variable is used in a similar fashion for the linker. Finally thePKG_CONFIG_PATH environment variable contains a search path thatpkg-config (see below) uses when looking for for file describing how to compile programs using different libraries. If you were installing GTK+ and it's dependencies into/opt/gtk, you might want to set these variables as:

      CPPFLAGS="-I/opt/gtk/include"      LDFLAGS="-L/opt/gtk/lib"      PKG_CONFIG_PATH="/opt/gtk/lib/pkgconfig"      export CPPFLAGS LDFLAGS PKG_CONFIG_PATH    

You may also need to set the LD_LIBRARY_PATH environment variable so the systems dynamic linker can find the newly installed libraries, and thePATH environment program so that utility binaries installed by the various libraries will be found.

      LD_LIBRARY_PATH="/opt/gtk/lib"      PATH="/opt/gtk/bin:$PATH"      export LD_LIBRARY_PATH PATH    

Dependencies

Before you can compile the GTK+ widget toolkit, you need to have various other tools and libraries installed on your system. The two tools needed during the build process (as differentiated from the tools used in when creating GTK+ mentioned above such asautoconf) are pkg-config and GNU make.

  • pkg-config is a tool for tracking the compilation flags needed for libraries that are used by the GTK+ libraries. (For each library, a small.pc text file is installed in a standard location that contains the compilation flags needed for that library along with version number information.)

  • The GTK+ makefiles will mostly work with different versions of make, however, there tends to be a few incompatibilities, so the GTK+ team recommends installingGNU make if you don't already have it on your system and using it. (It may be calledgmake rather than make.)

Some of the libraries that GTK+ depends on are maintained by by the GTK+ team: GLib, GdkPixbuf, Pango, ATK and GObject Introspection. Other libraries are maintained separately.

  • The GLib library provides core non-graphical functionality such as high level data types, Unicode manipulation, and an object and type system to C programs. It is available from theGTK+ FTP site or here.

  • The GdkPixbuf library provides facilities for loading images in a variety of file formats. It is availablehere.

  • Pango is a library for internationalized text handling. It is availablehere.

  • ATK is the Accessibility Toolkit. It provides a set of generic interfaces allowing accessibility technologies such as screen readers to interact with a graphical user interface. It is availablehere.

  • Gobject Introspection is a framework for making introspection data available to language bindings. It is availablehere.

External dependencies

  • The GNU libiconv library is needed to build GLib if your system doesn't have the iconv() function for doing conversion between character encodings. Most modern systems should haveiconv().

  • The libintl library from the GNU gettext package is needed if your system doesn't have the gettext() functionality for handling message translation databases.

  • The libraries from the X window system are needed to build Pango and GTK+. You should already have these installed on your system, but it's possible that you'll need to install the development environment for these libraries that your operating system vendor provides.

  • The fontconfig library provides Pango with a standard way of locating fonts and matching them against font names.

  • Cairo is a graphics library that supports vector graphics and image compositing. Both Pango and GTK+ use cairo for all of their drawing.

  • The shared-mime-info package is not a hard dependency of GTK+, but it contains definitions for mime types that are used by GIO and, indirectly, by GTK+. gdk-pixbuf will use GIO for mime type detection if possible. For this to work, shared-mime-info needs to be installed and XDG_DATA_DIRS set accordingly at configure time. Otherwise, gdk-pixbuf falls back to its built-in mime type detection.

Building and testing GTK+

First make sure that you have the necessary external dependencies installed: pkg-config, GNU make, the JPEG, PNG, and TIFF libraries, FreeType, and, if necessary, libiconv and libintl. To get detailed information about building these packages, see the documentation provided with the individual packages. On a Linux system, it's quite likely you'll have all of these installed already except forpkg-config.

Then build and install the GTK+ libraries in the order: GLib, Pango, ATK, then GTK+. For each library, follow the steps ofconfigure, make, make install mentioned above. If you're lucky, this will all go smoothly, and you'll be ready tostart compiling your own GTK+ applications. You can test your GTK+ installation by running thegtk3-demo program that GTK+ installs.

If one of the configure scripts fails or runningmake fails, look closely at the error messages printed; these will often provide useful information as to what went wrong. Whenconfigure fails, extra information, such as errors that a test compilation ran into, is found in the fileconfig.log. Looking at the last couple of hundred lines in this file will frequently make clear what went wrong. If all else fails, you can ask for help on the gtk-list mailing list. SeeMailing lists and bug reports(3) for more information.

Extra Configuration Options

In addition to the normal options, the configure script for the GTK+ library supports a number of additional arguments. (Command line arguments for the other GTK+ libraries are described in the documentation distributed with the those libraries.)

configure

[ --disable-modules | --enable-modules ]

[[--with-included-immodules=MODULE1,MODULE2,...]]

[ --enable-debug=[no/minimum/yes] ]

[ --disable-Bsymbolic | --enable-Bsymbolic ]

[ --disable-xkb | --enable-xkb ]

[ --disable-xinerama | --enable-xinerama ]

[ --disable-gtk-doc | --enable-gtk-doc ]

[ --disable-cups | --enable-cups ]

[ --disable-papi | --enable-papi ]

[ --enable-xinput | --disable-xinput ]

[ --enable-packagekit | --disable-packagekit ]

[ --enable-x11-backend | --disable-x11-backend ]

[ --enable-win32-backend | --disable-win32-backend ]

[ --enable-quartz-backend | --disable-quartz-backend ]

[ --enable-broadway-backend | --disable-broadway-backend ]

[ --enable-wayland-backend | --disable-wayland-backend ]

[ --enable-introspection=[no/auto/yes] ]

[ --enable-gtk2-dependency | --disable-gtk2-dependency ]

--disable-modules and --enable-modules Normally GTK+ will try to build the input method modules as little shared libraries that are loaded on demand. The--disable-modules argument indicates that they should all be built statically into the GTK+ library instead. This is useful for people who need to produce statically-linked binaries. If neither--disable-modules nor --enable-modules is specified, then theconfigure script will try to auto-detect whether shared modules work on your system.

--with-included-immodules This option allows you to specify which input method modules you want to include directly into the GTK+ shared library, as opposed to building them as loadable modules.

--enable-debug Turns on various amounts of debugging support. Setting this to 'no' disables g_assert(), g_return_if_fail(), g_return_val_if_fail() and all cast checks between different object types. Setting it to 'minimum' disables only cast checks. Setting it to 'yes' enables runtime debugging. The default is 'minimum'. Note that 'no' is fast, but dangerous as it tends to destabilize even mostly bug-free software by changing the effect of many bugs from simple warnings into fatal crashes. Thus--enable-debug=no should not be used for stable releases of GTK+.

--disable-Bsymbolic and --enable-Bsymbolic The option --disable-Bsymbolic turns off the use of the -Bsymbolic-functions linker flag. This is only necessary if you want to override GTK+ functions by usingLD_PRELOAD.

--enable-explicit-deps and --disable-explicit-deps If --enable-explicit-deps is specified then GTK+ will write the full set of libraries that GTK+ depends upon into its.pc files to be used when programs depending on GTK+ are linked. Otherwise, GTK+ only will include the GTK+ libraries themselves, and will depend on system library dependency facilities to bring in the other libraries. By default GTK+ will disable explicit dependencies unless it detects that they are needed on the system. (If you specify--enable-static to force building of static libraries, then explicit dependencies will be written since library dependencies don't work for static libraries.) Specifying--enable-explicit-deps or --enable-static can cause compatibility problems when libraries that GTK+ depends upon change their versions, and should be avoided if possible.

--disable-xkb and --enable-xkb By default the configure script will try to auto-detect whether the XKB extension is supported by the X libraries GTK+ is linked with. These options can be used to explicitly control whether GTK+ will support the XKB extension.

--disable-xinerama and --enable-xinerama By default the configure script will try to link against the Xinerama libraries if they are found. These options can be used to explicitly control whether Xinerama should be used.

--disable-xinput and --enable-xinput Controls whether GTK+ is built with support for the XInput or XInput2 extension. These extensions provide an extended interface to input devices such as graphics tablets. When this support is compiled in, specially written GTK+ programs can get access to subpixel positions, multiple simultaneous input devices, and extra "axes" provided by the device such as pressure and tilt information.

--disable-gtk-doc and --enable-gtk-doc The gtk-doc package is used to generate the reference documentation included with GTK+. By default support forgtk-doc is disabled because it requires various extra dependencies to be installed. If you havegtk-doc installed and are modifying GTK+, you may want to enablegtk-doc support by passing in --enable-gtk-doc. If not enabled, pre-generated HTML files distributed with GTK+ will be installed.

--disable-cups and --enable-cups By default the configure script will try to build the cups print backend if the cups libraries are found. These options can be used to explicitly control whether the cups print backend should be built.

--disable-papi and --enable-papi By default the configure script will try to build the papi print backend if the papi libraries are found. These options can be used to explicitly control whether the papi print backend should be built.

--disable-packagekit and --enable-packagekit By default the configure script will try to build the PackageKit support for the open-with dialog if the PackageKit libraries are found. These options can be used to explicitly control whether PackageKit support should be built.

--enable-x11-backend, --disable-x11-backend, --enable-win32-backend,--disable-win32-backend, --enable-quartz-backend, --disable-quartz-backend,--enable-broadway-backend, --disable-broadway-backend, --enable-wayland-backend, and--disable-wayland-backend Enables specific backends for GDK. If none of these options are given, the x11 backend will be enabled by default, unless the platform is Windows, in which case the default is win32. If any backend is explicitly enabled or disabled, no other platform will be enabled automatically. Other supported backends are the quartz backend for OS X.

--enable-introspection Build with or without introspection support. The default is 'auto'.

--enable-gtk2-dependency or --disable-gtk2-dependency Whether to rely on an exiting gtk-update-icon-cache utility instead of building our own. Distributions which are shipping both GTK+ 2.x and GTK+ 3 may want to use this option to avoid file conflicts between these packages. The default is to build gtk-update-icon-cache.


原创粉丝点击