Establish a GTK development environment in Linux (UBUNTU)

Source: Internet
Author: User

 

Establish a GTK development environment in Linux (UBUNTU)

Www.firnow.com time: Author: anonymous name Edit: This site click: 2260
[Comment]

--

 

1. Configuration
Gcc

Just installed system
GCC already exists, but no GCC file can be compiled, because there are no necessary header files, so install
Build-essential
Package, Installation
This package will be automatically installed
On G, libc6-dev, Linux-libc-Dev, libstdc 6-4.1-dev and some 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.

Int main ()
{
Printf ("Hello Ubuntu
! /N ");
Return 0;
}

$ GCC testc. C-o testc
$./Testc

Hello Ubuntu!

2. Install GTK

Method1: 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 gnome-Dev-Doc

----------------------------------------------------------------------
Method2:

Sudo apt-Get install gnome-core-devel # This will install libgtk2.0-dev libglib2.0-Dev and other development
Related library files

Sudo apt-Get install PKG-config # used to automatically find the header file and library file location when compiling the GTK Program

Sudo apt-Get install devhelp # This will install the devhelp GTK document
View programs

Sudo apt-Get install libglib2.0-Doc libgtk2.0-doc # This will install the GTK/glib api reference manual and other help documents

Sudo apt-Get instal Glade libglade2-dev # This will install the GTK-based interface constructor.

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

# 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 gtkhello. C-o gtktest 'pkg-config -- cflag
S -- libs GTK +-2.0'
$./Gtktest

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

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.