Under Linux want to do a graphical interface, and then choose to use gtk+2.0 to edit, My computer has been installed gtk+2.0, so on the Internet to find an installation method, the results are not tested, we have installation problems can say, together under discussion.
1, install Gcc/g++/gdb/make and other BASIC programming tools
sudo apt-get install build-essential
2, installation Libgtk2.0-dev Libglib2.0-dev and other development-related library files
sudo apt-get install Gnome-core-devel
3, used to automatically find the header file and library file location when compiling GTK program
sudo apt-get install Pkg-config
4. Install devhelp GTK Document Viewer Program
sudo apt-get install Devhelp
5. Install Gtk/glib API Reference manuals and other help documents
sudo apt-get install Libglib2.0-doc libgtk2.0-doc
6. Installing GTK-based interface GTK/C + + language graphics library for developing gnome windows
sudo apt-get install glade Libglade2-dev
7, install gtk2.0 or gtk+2.0 all the required files Shitong download installation completed
sudo apt-get install Libgtk2.0-dev
After installation, you can start writing the first simple program!
1#include <gtk/gtk.h>//must reference gtk/gtk.h this header file2 intMainintargcChar*argv[])//Declaration of the standard C language main function3 {4Gtkwidget *window;//declares a pointer to a window control where Gtkwidget is the gtk+2.0 control type. window is the variable name, regardless of the type of the variable5 6Gtk_init (&ARGC,&ARGV);//Initializing the GTK + environment is required in the GTK + program7 8window =gtk_window_new (gtk_window_toplevel);9 /*used to create a window. The function gtk_window_new creates a window and returns a pointer to the control of the window, where the pointer value is assigned to the variable of window, and the parameter gtk_window_toplevel indicates that the type is the topmost main window and a parameter Gtk_window_ Popup indicates that the window type is a pop-up borderless window*/Ten OneGtk_window_set_title (Gtk_window (window),"Hello World");//to set a caption for the Windows window A -Gtk_window_set_default_size (Gtk_window (window), -, -);//Set the window size -G_signal_connect (G_object (window),"Destroy", G_callback (gtk_main_quit), NULL); the /*Event listener function, meaning, for the object window, when the "destroy" time occurs, call the Gtk_main_quit function, pass the function parameter is null, that is, when you click the Window Close button, the end of the program*/ - -Gtk_widget_show (window);//Display the window created in the previous step - + Gtk_main (); - /*This function is the most critical, it is the main event loop of gtk+2.0, each gtk+2.0 program must have one or the program will not run*/ + returnFALSE; A /*The final logical return value of the code is false, which is equivalent to 0 of the integer type. */ at}
Such a simple program is completed, can be directly compiled with GCC, command for
GCC test.c ' pkg-config--cflags--libs gtk+-2.0 '
One of the last symbol and PKG before the symbol is ~ the same key symbol, cannot be written in single quotation marks, GCC this program, if you do not have any syntax error, will generate a a.out executable, and then you can happily run, you will find that after the execution of a program called Hello World window, which means your first program has been successful.
gtk+2.0 Simple learning of C graphical programming under Linux