Introduction to linux Program Development (1)

Source: Internet
Author: User

When chatting with friends on QQ a while ago, some people will always see that application development on Linux can be completed by experts, and this kind of "Superstition" seems to be quite common at present. However, this is not the case. In terms of library support, the Linux platform provides many powerful and rich libraries for user-level application development, and most of them are cross-platform Boost, OpenGL, STL, Qt, Java, etc.) and based on POSIX standard glibc ), at the same time, the Linux kernel also provides a fully functional kernel interface for driver development. From the aspect of development tools, Linux provides a powerful compiler GCC and Debugger GDB, with their help, we can easily develop portable applications on Linu x. In this case, why did "Superstition" come from? I think, on the one hand, due to the fact that there are few books describing various types of Linux development in detail, various Linux applications are still not popular in China, on the other hand, because many people have installed a Linux, I was overwhelmed by the fact that I couldn't find a handy IDE environment. After all, many of us are used to writing a program and press F5, and the rest of the task will let the IDE act as a proxy. In fact, it's okay if you want to do this in Linux. Now that we have talked about IDE, let's start with it. I believe that choosing a good IDE environment is a good start for your entire learning process.

The tool must be used first when the job wants to do its best-IDE

In fact, there are many powerful IDE environments in Linux, because in a sense, Linux is an operating system designed for developers. This is of course indispensable, here we will introduce you to some commonly used ides.

KDevelop

This is an IDE developed with Qt. The main Supported languages are C/C ++,

Eclipse

In recent years, eclipse has developed rapidly. It is not only a java-based development platform, but also a powerful plug-in architecture that allows it to be used as a variety of applications. As a carrier of various plug-ins, eclipse provides a complete GUI interface, allowing you to focus only on what you want to do with eclipse.

Emacs

VIM

Shan Gao, Yue Xiao, the story of IDE background GCC

We briefly introduced some IDE environments, in which all C/C ++ related programs are compiled by GCC, however, IDE only plays a role in collecting compilation information and generating makefile for our project, which will be mentioned later ). C is still the mainstream language for system development due to the features of Linux development. Therefore, it is necessary to have a comprehensive understanding of GCC. Once the IDE cannot meet your needs, we must have the ability to create programs manually, and for the purpose of learning, we usually do not need complex files generated by IDE. It is obviously redundant to generate more than 2 MB files for a Hello world.

The full name of GCC is GNU Compiler Collection. From this name, we can see that GCC represents a set of compilers. Currently, GCC supports C, C ++, and Objective-C, objective-C ++, Fortran, Java, and Ada. However, for general considerations, we will only discuss C/C ++ in GCC.

Currently, the latest version of GCC is 4.0.0. However, due to the use of new technologies and new encoding specifications, many old codes must be modified before compilation. Therefore, this version is not recommended. The relatively stable new version is currently 3.4.4. You can download it on the GNU homepage. So where is GCC powerful? How can I use it? The following is a few simple and practical examples to show you the powerful functions provided by GCC.

Familiarize yourself with the basic usage of GCC through Helloworld Compilation

It seems that a Hello World sample program for all new languages has become an unwritten standard through which people can understand some basic elements of the language. Here, we use a Hello World to see how to generate executable files with GCC.

Save the above file as helloworld. c. Then open the console and enter the following command gcc helloworld. c-o helloworld. If everything works properly, there should be no output on the console. Use ls to view your working directory. You will find an executable file named helloworld is added to the directory, and then run./hellworld

The output of this program is displayed.

It's easy, isn't it? But friends who have learned computer should know, the compilation process of a program is divided into the process shown in. The strength of GCC is that it allows you to stop and view intermediate results in any process shown above and control it.

1. preprocessing is first a preprocessing process. The-E Option of GCC enables GCC to stop compilation after preprocessing and print the files after preprocessing to the standard output. The following-o specifies the name of the output file.

Gcc-E hellowrold. c-o helloworld. cpp contains part of helloworld. cpp. We can see that the file already contains content in stdio. h.

If we want to execute the next compilation process, we can continue to use the GCC-x Option, which is used to display the suffix of the specified file, rather than letting the compiler determine based on the Suffix from the row ). We usually use the following types of language types (for more complete parameter descriptions, refer to GCC manual ):

L c-header c-cpp-output

L c ++-header c ++-cpp-output

L assembler extends er-with-cpp

In addition, the following table lists common GCC suffixes.

Of course, you can also omit the language type part. At this time, GCC will judge the part based on the file suffix, just as you did not use this option.


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.