Walking into the door of Linux programming

zhaozj2021-02-16  43

A little experience in the programming of my beginner Linux is shared with you. Published in "Computer Lovers" 2001 No. 5. Looking at my current eyes, this article is really not worth mentioning!

====

With the continuous spread of Linux, more and more people using Linux, there are many programming enthusiasts. But many people have just learned the basic operations of Linux, and they have doubtful to programming this technology: how to design in Linux, what kind of development tools? This article takes a loss of Linux programming and everyone to discuss issues related to Linux programming. As a free operating system, Linux has become the biggest feature of the source, which we can easily get the source code of the Linux system and its application. Linux program is also written in such an environment or The modified work, learned Linux programming, not only can write some shared small programs for everyone, or make a little modification of existing software, allowing them to be more suitable for yourself. There are many tools programmed under Linux. Different versions of Linux also provide different development tools. Commonly used languages ​​are generally C / C , usually Linux provides the C language compiler GCC under the console terminal. As long as we create a C language source program file, such as Hello.c, then run under the terminal: GCC Hello.c, the system will automatically compile the program. If there is no error, generate a.out file in the current directory, otherwise Display an error prompt. After generating a.out, we only need to type ./a.out can run this program. However, the development of such a text command is really inconvenient, so now many versions of Linux provide us with the integrated development environment under the X-Windows graphics interface, such as KDevelop, the blue dot Linux environment, etc., these integrations The environment not only provides us with a good programming interface, but also provides great benefits for programming work. When you run KDevelop for the first time, the system will automatically run the KDevelop setup installer. This program will verify that the files necessary to run KDevelop are complete. After setting, we can start using it. KDevelop shows our integrated development environment similar to Visual C under Linux (see Figure 1). There are several labels such as CV, LFV, RFV, and a list of class lists, logical file lists, and actual file lists, which are mainly included in the left half of this environment. The right half of the development environment is the document display area, which is used to display the source or help information. Below we will use this development tool to develop two applets and try the feeling of Linux programming. Let's try to use it to make a simple and most classic "Hello World!" Program, which is running in the terminal of Linux, like the first program developed when you beginch C language - in DOS Like the "Hello World!" Running. First open the "Project" menu, select "New ...", select "Terminal Program-C Program" in the pop-up Application Wizard (if you are familiar with the use of C programs, you can choose C programs here, but the later program list is I have to modify it) and click Next. " Enter information such as the name of the project in the second page of the wizard, then remove the "generation source file and header file" (see Figure 3). If this is not doing this, Application Wizard will automatically generate some source code, and it is also the "Hello World" program we have to do, but we don't look at this for explaining the problem, we do it yourself.

Click the "Generate" button, wait a little, after the screen appears Ready, click the "Exit" button, our project is generated. Next, we have to enter the source program. Select the "New" command in the file menu, create a new "C / C program" (our example is a C program), the system automatically generates an empty file according to the file header template selected in Application Wizard, we will put the following The program enters this file. When entering, pay attention to the case, the C language is sensitive to the case: #include main () {printf ("Hello World! / N");} learned C language Friends must be familiar with this code, which is indeed a classic program, almost all C language has it. Then, we select the "Run" command in the menu or toolbar, perform this program, after a period of compilation, the program runs in the terminal, outputting "Hello World!". Don't look at this program is very simple, but it is indeed the first program we made in the Linux environment. The C and ANSI C under Linux are completely compatible, and those who have learned C programming cannot be said to be good news. Are you already a big interest in Linux program? However, this program is too simple, can you be a graphics program running under X-window? Do you have such a program? Don't worry, Try me with me. To write a graphics, an excellent development package is essential. Like the MFC class library in VC , KDevelop is programmed under Linux to provide a powerful QT library and KDE libraries, which can be easily written by the KDE graphical interface program under X-WINDOW. In addition, KDevelop also provides a series of practical tools such as "dialog editor" to make development graphics more convenient. As in the above, let's develop a graphic version "Hello World" program under X-window. We choose to use a relatively simple QT library to write our program, let's experience this powerful and easy-to-use development kit. The first step is to establish an engineering document, method and engineering files that establish terminal programs in front. Different is that in the first step in Application Wizard is no longer a "terminal program-C program", but "Qt program - ordinary " After the project is built, we can write the program. CHAR ** Argv) {QApplication A (Argc, Argv); QPushbutton Hello ("Hello World!"); Hello.resize (100, 30); a.setmainwidget (& Hello); hello.show (); returnif EXEC ();} This program is more complicated than the previous C procedure, but it is not tight, and our line is analyzed. Two header files in front of the program are called, where QApplication.h is the most basic library required to establish a QT program, and any QT program is used.

转载请注明原文地址:https://www.9cbs.com/read-20978.html

New Post(0)