Install and configure Gtk and Qt compiling environments in Ubuntu

Source: Internet
Author: User
Tags gtk

Install and configure Gtk and Qt compiling environments in Ubuntu (the system environment is Ubuntu 12.04)

1. Configure the basic development environment GCC

GCC already exists in the newly installed system, but almost no GCC file can be compiled. Because some necessary header files are missing, you need to install the build-essential software package. You can search for build-essential in the new version or enter the following command:

Sudo apt-get install build-essential program example

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

Program example:

Hello. c

# Include <stdio. h>
Int main ()
{
Printf ("Hello Ubuntu! ");
Return 0;
}

Compile and run:
$ Gcc testc. c-o testc
$./Testc

Output:
Hello Ubuntu!

2. Install the GTK/GNOME Development Environment
To install the GTK environment, you only need to install libgtk2.0-dev. to install the gnome development environment, you need to install gnome-core-devel, which contains the GTK development kit. But in general, we need an ide development environment and a help file, so we install
Sudo apt-get install gnome-devel-docs
Program example
After the installation is complete, we also make a test program (CodeLanguage: C, only 1 header file)

Hello-ubuntu_gnome.c

# Include <gtk/gtk. h>
Void hello (GtkWidget * widget, gpointer data)
{
G_print ("Hello Ubuntu! \ 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 Ubuntu! ");
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);/* display a window */
Gtk_main ();/* enter the main loop */
Return (0 );
}

Compile and run the following command:

$ Gcc gtktest. c-o gtktest 'pkg-config -- cflags -- libs gtk +-1000'

$./Gtktest

// 'Pkg-config -- cflags -- libs gtk +-2.0 'Library Reference

A window with a button is displayed. click the button to close the window. The command line displays HelloUbuntu!

Next, let's take a look at the highlights of page 2nd:

  • 1
  • 2
  • Next Page

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.