Getting started with GTK2: Build the GTK2 environment in Ubuntu

Source: Internet
Author: User
I am using Ubuntu10.10 different versions may be different. 1. GCC is already available in the newly installed GCC system, but this GCC file cannot be compiled because there are no necessary header files, so to install the build-essential Package, installed with this package will automatically install on g ++, libc6-dev, linux-libc-dev, libstdc ++ 6-4.1-dev and other required software and header file libraries. Search for build-e in the new version.

I use Ubuntu 10.10 in different versions.

1 configure GCC
The newly installed system already has GCC, but no GCC file can be compiled. Because there are no necessary header files, you need to install the build-essential software package, installed with this package will automatically install g ++, libc6-dev, linux-libc-dev, libstdc ++ 6-4.1-dev and other necessary software and header file library.
You can search for build-essential in the new version or enter the following command:

Sudo apt-get install build-essential

After the installation is complete, write a c language program testc. c to test it.

C ++ code
# Include
Int main ()
{
Printf ("Hello Sina! \ N ");
Return 0;
}


$ Gcc testc. c-o testc
$./Testc

Display
Hello MM!
In this way, the C language compiler is successfully installed;

2. Install the GTK Environment [Linux community www.linuxidc.com]

To install the GTK environment, you only need to install a gnome-core-devel, which integrates many other packages. In addition, some other things need to be transferred, such as libglib2.0-doc, libgtk2.0-doc help document, devhelp help document view, glade-gnome, glade-common, and glade-doc graphic interface design.

Sudo apt-get install gnome-core-devel
Sudo apt-get install libglib2.0-doc libgtk2.0-doc
Sudo apt-get install devhelp
Sudo apt-get install glade-gnome glade-common glade-doc

After the installation is complete, we also make a test program.

Code:
C ++ code
# Include
Void hello (GtkWidget * widget, gpointer data)
{
G_print ("Hello GClinux! \ N ");
}
Gint delete_event (GtkWidget * widget, GdkEvent * event, gpointer data)
{
G_print ("delete event occurred \ n ");
Return (TRUE );
}
Void destroy (GtkWidget * widget, gpointer data)
{
Gtk_main_quit ();
}
Int main (int argc, char * argv [])
{
GtkWidget * window;
GtkWidget * button;
Gtk_init (& argc, & argv );
Window = gtk_window_new (GTK_WINDOW_TOPLEVEL );
Gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL );
Gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL );
Gtk_container_set_border_width (GTK_CONTAINER (window), 10 );
Button = gtk_button_new_with_label ("hello www.linuxidc.com! ");
Gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (hello), NULL );
Gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (window ));
Gtk_container_add (GTK_CONTAINER (window), button );
Gtk_widget_show (button );
Gtk_widget_show (window );
Gtk_main ();
Return (0 );
}

Compile and run the following command:

Code:
$ Gcc gtkhello. c-o gtktest 'pkg-config -- cflags -- libs gtk +-1000'
$./Gtktest

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.