The c/c environment in ubuntu is relatively simple to build, because of the help of apt and the new.
1. First, configure gcc. gcc has been installed on ubuntu. (gcc is a Compiler in linux developed by Stallman, the father of GNU, called GNU Compiler Collection, currently, compiled languages include C, C, Objective-C, Fortran, Java, and Ada .). however, gcc cannot compile files. because some header files are missing. we need to configure these header files. here we need to install the build-essential package, which will automatically install on g, libc6-dev, linux-libc-dev, libstdc 6-4.1-dev and other required software and header file libraries.
Install build-essential. You can search for the new version and install it or enter the following in the terminal:
Sudo apt-get install build-essential
2. In addition to the compiler, we also need a text editor. because we need to edit the c program code. in fact, ubuntu has its own editor. We can create a document. enter the code and change the name *. c. you can also use another text editor vi. if your ubuntu does not have. then we can enter:
Sudo apt-get install vim-full
After that, we have a very powerful editor vi.
3. After completing the above two steps, you can start to compile the first C language program in ubuntu.
In the main folder, create a hello. c file and double-click the file and enter the code:
# Include <stdio. h>
Int
Main (void)
{
Printf ("Hello, ubuntu! ");
Return 0;
}
Save.
Alternatively, you can enter: gvim hello. c on the terminal.
Then enter the code to save it.
Enter the following information on the terminal:
Gcc-Wall hello. c-o hello
If no error is found, enter./hello.
In the terminal, you can see your program output:
Hello, ubuntu!
4. If you want to compile c, you need to create a *. cpp file, and enter the following in the terminal:
G-Wall file. cpp-o file
./File
5. graphical environment Configuration
Install the GTK Environment
You only need to install a gnome-core-devel, which integrates many other packages. In addition, some other things, such
Libglib2.0-doc, libgtk2.0-doc help document, devhelp help document view, glade-gnome, glade-common,
Glade-doc graphic interface design.
Enter the following command on the terminal:
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
Create a test program after installation
Program code
# Include <gtk/gtk. h>
Void hello (GtkWidget * widget, gpointer data)
{
G_print ("Hello Ubuntu! ");
}
Gint delete_event (GtkWidget * widget, GdkEvent * event, gpointer data)
{
G_print ("delete event occurred ");
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 );
}
Enter at the terminal:
Gcc gtkhello. c-o gtktest 'pkg-config -- cflags -- 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!