The first Linux programming is worth remembering

Source: Internet
Author: User
The first Linux programming is worth remembering-Linux general technology-Linux programming and kernel information. The following is a detailed description. Today, I took a look at the "GCC usage and Development" section in "Linux System Application and Development tutorial". I have been familiar with Linux for a short time, but there are still few things that really understand Linux, now let's play with Linux programming.

The official version of Fedora 7.0 installed two days ago. After the system is started, a new empty file helloworld is created. c. The simplest program code for beginners (although I have been learning C for more than two years)

# Include
Void main ()
{
Printf ("Hello World! \ N ");
}

Save and enter the command "gcc helloworld. c-o helloworld ", press enter immediately, and think that your first Linux program will be born. Oh, My god. Which of the following is an error message indicating that the main function does not return the int type, but the above Code is feasible in VC. No way, change

# Include
Int main ()
{
Printf ("Hello World! \ N ");
Return 0;
}

Run the command again to generate the command. There is no prompt this time. The command is successful. Haha ~~~ Run your first Linux program and check the result. Enter "helloworld" in the terminal. Oh, My god. If this command is not displayed, the program is in the current directory, after reading a book, I finally found that I needed to write the command ". /helloworld ", press enter, and finally print" Hello World!" . Although I have been writing programs for nearly three years, I have printed "Hello World!" on Linux !" Still in trouble, this is the reason for not doing it.

Next, write an interesting form program, use GTK + in the book, and change the helloworld. c code

# Include
Void on_btn_clicked (GtkWidget * widget, gpointer data)
{
G_print ("Hello World! \ N ");
}
Void on_delete (GtkWidget * widget, GdkEvent * event, gpointer data)
{
G_print ("Window Closed. \ n ");
Gtk_main_quit ();
}
Int main (int argc, char * argv [])
{
GtkWidget * window;
GtkWidget * button;
Gtk_set_locale ();
Gtk_init (& argc, & argv );
Window = gtk_window_new (GTK_WINDOW_TOPLEVEL );
Gtk_container_set_border_width (GTK_CONTAINER (window), 10 );
G_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (on_delete), NULL );
Button = gtk_button_new_with_label ("Hello World ");
G_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_btn_clicked), NULL );
Gtk_container_add (GTK_CONTAINER (window), button );
Gtk_widget_show_all (window );
Gtk_main ();
Return 0;
}

It's all such a long function name, and there are so many underscores. After reading it, I finally typed two wrong words, which was prompted during compilation. After coding, follow the command "gcc helloworld. c-o helloworld 'pkg-config gtk +-2.0 -- cflags -- libs '". After you press enter, the system prompts" pkg-config gtk +-2.0 -- cflags -- libs ", the book says "pkg-config gtk +-2.0 -- cflags -- libs" to check its output results. If you enter a carriage return, a bunch of characters are displayed. I don't know what to use. Try the above compilation command again, or the same error. Why? Is there an incorrect typographical command in the book? Open Firefox right away, Baidu. I can see that the commands used by others are a little different from those I typed, that is, the single quotes. I typed regular single quotes in English, how strange is it when someone else uses a "single quotation mark" on the right? The book also says that the use of a pair of reverse single quotes, I can not find any reverse single quotes where the input, the others Copy, into "gcc helloworld. c-o helloworld 'pkg-config gtk +-2.0 -- cflags -- libs' ", copy the command to the terminal, press enter, wait for a while, and there will be no final result at all, success! What is the reverse single quotes? I tried the keyboard and couldn't find any reverse single quotes. Run the first Linux form program and enter ". /helloworld ", press enter, haha, the form is coming out, there is only one ugly button, a very small form, almost cannot find where it appears, it is more strange to maximize, because the button also grows, haha.

This is the first Linux programming failure! Restart Windows 2003 and write this article. (Oh, by the way, the reverse single quotation mark shows me at this time. It is a very rare symbol and also on a very few buttons, that is, the one under the Esc key in the upper left corner of the keyboard, this is called reverse single quotes, haha)

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.