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 is already installed on Ubuntu. (GCC is a compiler in Linux developed by Stallman, the father of GNU. It is called GNU.
Compiler Collection, which can be compiled in the following languages: C, C ++, objective-C, Fortran, Java, and
Ada.). But GCC still cannot compile files. Because some header files are missing, we need to configure these header files. here we 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 headers
Parts Library.
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 your first C language program on 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! \ N ");
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. Then input 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! \ 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 );
}
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!