Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of Linux and Arm-Linux program development

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what are the methods of Linux and Arm-Linux program development". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the methods of Linux and Arm-Linux program development?"

A brief introduction to the Arm-Linux program development platform

The development of Arm-Linux programs is not like the Windows program development that we have come into contact with before, the construction of the platform is much more tedious, so before officially entering the program development, this development mode is briefly introduced, so that a programmer who does not have any Linux development experience can understand the following content.

1.1 system and development language required for program development

At least three systems are required to develop arm-linux programs:

Windows system.

Mainly used for file transfer and some simple text file editing. In fact, this system is not necessary, just because the most popular system on the PC is still the Windows system, many of our operating habits about PC files and data are formed on the Windows system, and have formed a serious dependence on it, so the Windows system plays the role of "auxiliary development system".

PC-Linux system.

After installing the arm-Linux cross-compiler on this system, the code text file can be compiled to generate an executable program that can be run in the arm-Linux system. This system is called "Linux host", and our development of Linux programs (including coding, debugging and compiling to generate executable files) is basically carried out on this system.

Arm-Linux system.

The platform on which the Arm-Linux program runs. The hardware carrier of this system is a small embedded arm board. After we develop the program on the Linux host and compile the arm-linux executable program, we transfer the executable program file to the embedded arm board, and then we can run the program directly on the arm board.

The functions and links of the three systems are shown in the following figure:

The functions and operation of each system and how to transfer and communicate files are described in detail later.

With regard to the development language, because the compilers and libraries provided by the Arm-Linux embedded boards currently purchased are all compiled and stored by Cmax Clipper +, it is generally chosen to design the program.

1.2 the way to build the system platform

There are two ways to build "three systems": a combination of three discrete single-system machines or a dual-system PC and a single-system Arm board machine. However, no matter which combination mode is adopted, the functions of all kinds of systems are the same, and they all transfer and communicate files through network protocols such as FTP, Telnet or SSH.

The combination mode of "three machines". Install the three systems on three machines and set up a local area network for the three machines.

"two machines" combination mode. On the PC, the virtual workstation can run two systems at the same time, and the Linux system on the virtual machine can basically complete all the tasks of all the physical PC-Linux machines, and of course, it can also set up a local area network.

Combined pattern diagram of "three machines"

Combined pattern diagram of "two machines"

If developers have high requirements for machine performance, it is recommended to use the "three machines" combination mode. Because the "two-machine" combination mode requires one machine to run dual systems, each system needs to allocate certain hardware resources, which may affect the smooth programs that each system runs.

If developers only do some simple program development, it is recommended to adopt the "two-machine" combination mode. In this way, the investment of hardware equipment can be saved, and the construction of development environment, development process and so on will be simpler. And the following content is based on this "two-machine" combination of development model.

2. Construction of Linux development platform

2.1 install a virtual workstation

At present, there are many popular virtual workstations, so it is recommended to use VM-ware WorkStation. The purpose of establishing a virtual workstation is to make a machine run many different types of systems at the same time, and it is convenient for developers to develop applications across platforms.

(with regard to VMware, you can search the Internet for a detailed description and usage, which will not be repeated here.)

2.2 install the Linux virtual machine

The process of installing a virtual machine is the same as installing a physical machine, except that the virtual machine installation is opened and installed from VMware. First prepare the Linux installation file, you can generally download the iso installation file to Linux on the Internet, and then install the system from VMware.

(detailed steps for virtual machine installation can be found online, which will not be repeated here.)

Here are some suggestions:

1. Install Fedora-10 and select full installation, that is, check all packages and options. In this way, after the installation, the system comes with a lot of development tools and related libraries to avoid re-building the tedious basic development platform.

two。 Configure hardware resources for the virtual system in VMware. It is recommended to allocate 16g of hard disk space and more than 1G of memory. Because the main Linux program development work in the future is carried out on the virtual machine, in order to ensure the smooth operation of the virtual machine, it is necessary to allocate rich hardware resources.

After the virtual machine is installed from the ISO file for the first time, a series of files are generated under the installation directory. After backing up these files, it takes several hours to install the virtual machine from ISO when installing the virtual machine on other machines. Copy the files in this directory to the appropriate directory (the same directory was set when installing from ISO for the first time). Then you just need to open the files in this directory from VMware.

Execute [View]-[Home] in VMware Workstation, bring up the Home view, and then open the virtual workstation system file.

When turned on, you can see the hardware resource configuration of a virtual machine. Some of these parameters can only be configured when using iso installation for the first time, such as hard disk size. Other parameters, such as memory size, shared directories, and so on, can be changed manually at a later time.

(set up the content in detail, you can find a lot of related content on the Internet, so I won't repeat it here.)

The difference between the two methods is the difference between the WinXp installation disk and the Ghost disk.

After installing Fedora, you can start the Fedora Linux system from the virtual workstation. The system desktops are as follows:

2.3 some basic configurations of virtual machines

After the virtual machine is installed for the first time, turn on the virtual machine, the default resolution is 800mm 600, and there is no omnipotent shared directory. In order to obtain a better operating interface and facilitate file sharing and transfer, some basic configurations are needed.

2.3.1 create a shared directory

Two systems running on the same hardware PC. Windows entity system is used for general purposes, such as networking, processing documents, etc.; Fedora Linux virtual system is used to develop Linux programs and compile to generate executable files.

You need to install vmware tools first.

On VMware, select the menu [VM]-[Install VM tools], and the directory / media will be generated on the Linux virtual machine, and a rpm file will be generated inside.

Then open the control terminal and su to log in to the superuser:

Cd / media

Rpm-ivh VMwareTools-7.8.5-156735.i386.rpm

Cd / usr/bin

Then see wmware-config-tools.pl under / usr/bin

Then enter wmware-config-tools.pl in Teminal

And then go all the way back to the car. Then you can set up a shared directory in the future.

(the detailed process can also be searched for relevant content on the Internet)

The advantage of shared directories is that these files can be extracted from the Windows system, and then network transfer and other command operations can be carried out through the familiar windows system. This setting will be mentioned later in the development of the program.

Create a shared directory in VMware and execute the menu command [VM]-[Settings... ]

Then you can find the corresponding shared directory in the Linux virtual machine file system: / mnt/hgfs/xplinux

The establishment of a shared directory can facilitate file exchange between virtual machines and physical machines. For example, we can place the compiled execution files on the Linux machine into a shared directory, which can then be extracted by the Windows machine and transferred to the arm-linux embedded board over the network.

2.3.2 adjust desktop resolution

Adjust the virtual machine desktop resolution in the VMware workstation. Generally speaking, the default is 800mm 600, and the current display is generally 10240768 or higher. Take my current computer monitor as an example, the resolution is 1440mm 900. Need to make appropriate adjustments to the desktop resolution of the virtual machine, and then full screen, then you can get a more friendly interface.

Start the virtual machine in VMware, and the login interface after the virtual machine boot is as follows:

Then log in to the system, set the resolution, system menu:

[System]-- [Preferences]-- [Hardware]-- [Screen Resolution]

Once the resolution is set, you can get a full-screen Linux interface.

2.3.2 other Settings

For example, setting the desktop background, the system font, and the mode of the resource manager, and so on, you can go to the field and be familiar with them.

2.4 install softwar

Although Fedora already comes with some necessary software, such as Open Office office software, gedit notepad software, Firefox web browser and so on. But since it is an operating system, we can also install some of the software we need. For example, Chinese input method (such as: small penguin input method), chat tools (such as QQ) and so on.

Note: su superuser privileges need to be enabled when installing programs in Terminal terminals.

III. Fedora-linux system

After the Fedora-linux virtual machine is installed and set up, you can begin the program development process. When you officially start program development, you also need to give a brief introduction to some of the basic programming tools of Linux, of course, if you already have this foundation, you can skip this chapter directly.

3.1 basic operating commands of the control terminal

Execute the system menu command [Applications]-[System Tools]-[Terminal], and open the Terminal terminal:

People who are familiar with the DOS interface of the Windows system will certainly be familiar with this operating terminal. By entering commands in Terminal, users can easily complete a series of operations under Linux. Before officially entering independent programming, it is necessary for users to be familiar with some of the most basic commands below (other commands look up relevant information on the Internet when the project needs).

File operation command

Creation, modification, replication, deletion, movement of files / folders, etc. (such as rm/mv/vi/cat, etc.)

Network setup command

Personality IP, open FTP, open Telnet, open SSH, and so on. (such as ifconfig/telnetd, etc.)

User management command

System user addition, deletion, password modification, and so on. (e. G. addusr/passwd, etc.)

File compilation command

This involves the establishment of the compilation environment, which will be introduced in detail when we formally enter the independent programming later.

This involves the establishment of the compilation environment, which will be introduced in detail when we formally enter the independent programming later.

Although Fedora provides users with a good user interface, Linux was originally developed from the command line operating system, and many powerful functions need to be realized by Terminal control terminals, so it is necessary for developers to be familiar with and proficient in these basic commands.

3.2 introduction to programming tools

If you choose to install Fedora completely, the system will come with a lot of development tools. Among them, Fedora-Eclipse CDT and Qt library and related designer Qt Designer are the main tools that we develop in the future.

Of course, if users do not choose a secure installation, they can download the installation files of various development tools online and install them themselves.

3.2.1 Fedora-Eclipse CDT

Execute the system menu in Fedora [Application]-- [Programming]-- [Eclipse]

Then you can see the startup screen of Fedora Eclipse.

Then there is the IDE environment of Eclispe. For those who have experience in Java programming under Windows, this interface is all too familiar and can be transferred directly to the development of Cmax Candle + programs under Linux, which greatly reduces the learning cycle of programmers.

Eclipse benefits, the first is open source, the second is free, the third is cross-platform.

Because of open source, it is very extensible, Eclipse is actually an omnipotent program development environment, you only need to reference the relevant language libraries in the settings and connect to the corresponding compiler, you can develop programs based on any language; because it is free, you do not need to register software and other trifles. Because of cross-platform, when users design cross-platform programs, the learning cycle can be greatly reduced.

Under the Windows platform, Eclispe is generally used as a Java development environment to develop Java desktop applications and Jsp web applications and even the popular Android mobile terminal software. After connecting to the library compiler under Linux under Linux, it becomes the development environment under Linux. After installing JDK under Linux, you can design Java programs under Linux. If you install tomcat web server for Linux system, you can develop web applications under Linux. If you install mysql database services for Linux, you can develop web applications. The database connection operation can be carried out, and so on (because our current goal is mainly to develop arm-linux window programs, so we mainly study on C _ hand Cards +).

3.2.2 Qt Library and Qt Interface Design Software

If you just write the CumberCraft + console software, you only need Eclipse CDT to solve the problem. But if you want to do windowing programming, you need to reference some open source interface libraries. For example, the popular Qt library at present.

Qt is a cross-platform C++ graphical user interface application framework developed by Nokia. It provides application developers with the functionality they need to build an art graphical user interface. Qt is fully object-oriented, easy to extend, and allows true component programming. Basically, Qt is the same type of thing as Motif,Openwin,GTK on X Window and MFC,OWL,VCL,ATL on Windows platform, but Qt has the advantages of excellent cross-platform characteristics, object-oriented, rich API, a large number of development documents and so on.

Set the Build option of the project in Eclipse, connect to the Qt library, and then you can develop the Qt program under Linux.

Because Eclipse does not provide a visual form program designer, with the help of third-party tools, QtDesigner can solve the UI design problems of Qt and compile the corresponding * .h and * .cpp files (the specific steps will be described in detail below).

As the saying goes, "if you want to do good work, you must first sharpen its tools." A lot of space has been spent on the previous introduction, all for the purpose of "sharpening the knife." now we are beginning to enter the link of "chopping firewood". The following will introduce the general methods of Linux and arm-linux program development using Eclipse CDT as the development environment.

4. Develop Linux programs with Eclipse CDT

4.1 establish a console program

Establish the "Hello World" console program based on C++ with Eclipse CDT.

Open the Eclipse development environment. Execute [File]-- [New]-- [C++ Project]

Then go to the C++ Project wizard with the Hello World template for C++

Click Finish, and Eclispe will create a C++-based HelloWorld project. After running the program, you can output "HelloWorld" in the console:

Note: if you are developing the console program, you don't need to do any other design, you just need to write C++ code directly, and you don't have to set up the compilation, library and compiler. Eclipse has automatically completed these contents for us.

4.2 establish a Linux window program

Just like in the Window environment, if we want to develop window programs with C++, we usually need to use Windows API or MFC. Similarly, in the Linux environment, we may refer to the Qt library in the C++ project to develop window programs under Linux.

In the full version of Fedora, there is a library of Qt that comes with it, under the directory / usr/lib:

The system comes with two versions of the Qt library qt-3.3 and qt4 by default, and generally we use qt-3.3.

To write a window program, we only need to set up the path of C++ Build + Build to point to the library of qt-3.3 in the case of the establishment of Cmax Build. The main development process is as follows:

Step 1: use Eclipse CDT to establish C++ Project.

Step 2: set the Build path to point to Qt. Right-click on the project file in the Project Manager to set the project properties, and set them in the Tool Settings of the Settings of C _ Settings + Build.

[GCC C++ Compiler]-- [Directories] add the included file path: / usr/lib/qt-3.3/include. This is the header file path included in C++ 's compiler, so be sure to set it because it is the established C++ Project.

[GCC C Compiler]-- [Directories] add the included file path: / usr/lib/qt-3.3/include. This is to set the header file path included by the C language compiler, because sometimes C++ will take into account some C language syntax and keywords, so it is best to make relevant settings.

[GCC C++ Linker]-- [Libraries] add the library path referenced at compile time: / usr/lib/qt-3.3/lib (note: do not write as include). And set the library search command parameter: qt-mt.

Step 3: write a C++ program that references the Qt library.

Step 4: run the program.

The running effect of the program is as follows:

Conclusion: through the introduction of the console program and window program under Linux, we have a simple understanding of the simple program development process under the Linux system. Let's start with the development of the arm-Linux program.

5. Use Eclipse to develop Arm-linux programs

5.1 Arm-linux hardware platform

The Arm-Linux machine uses the FL2440 development board of Feiling embedded Technology Company. When the Feiling company buys the development board, it will give you the relevant introductory tutorial "Feiling Development Board matching tutorial" along with the development board, along with a CD-ROM with a variety of development resources related to writing FL2440.

Before officially entering the program development, be familiar with the FL2440 development board and arm-linux system.

Fl2440 development board: familiar with the use of Bootloader, learn to burn the kernel, burn the file system and so on.

Arm-linux system: familiar with using some commands related to file system and network settings. If you already know something about Linux commands, the commands on arm-linux are pretty much the same.

(please refer to the book "Feiling Development Board matching tutorial" for detailed operation.)

5.2 develop console programs

The main development flow chart is as follows:

In the early development environment, the c or cpp file was written in a text editor, and then the code text file was compiled and the executable program was generated directly on the Linux machine through the cross-compilation command, and then the executable program was transferred to the arm-linux board, and then the program can be run on the arm-linux machine.

The current development model is the same as the earlier development model, except that it has been improved on the tools for writing code. Early coding tools can be done as long as they are software that can edit text, even through terminal vi commands in Linux. The function of the Linux machine is only to write code and compile code. Now with Eclipse CDT, you can write and debug Candle Candle + code on a Linux machine, and a Linux machine can basically simulate the running environment of most other programs on an arm-linux system except for some hardware-related applications, such as drivers.

5.2.1 write code using Eclipse CDT

In fact, it is exactly the same as writing a console program in Linux environment with Eclipse CDT. Except for some special occasions, such as writing drivers, you need to pay attention to the differences, the other functions are implemented in basically the same way.

This aspect belongs to the basic skills of programming, which requires long-term learning and accumulation, so I won't mention it any more here.

5.2.2 establishing a cross-compilation environment

Although the source code of the generated program is the same, the executable file compiled on the Linux machine cannot run on the arm-linux system. It needs to be compiled with a special compiler for arm-linux before the executable file that can be run on the arm-linux system can be generated. Of course, at this time, the application obviously can not run on the Linux system.

Transfer the cross-compilation tool cross-2.95.3.tar.bz2 (which can be downloaded from the Internet or found in the CD resources attached to the development board) to the Linux system through a shared directory, then enter its file directory in the Linux system terminal, and then execute the decompression command:

Tar xjvf cross-2.95.3.tar.bz2

Then you can see the unzipped 2.95.3 library in the / usr/local/arm file directory, or if you unzipped the cross-3.4.1.tar.bz2 version, 3.4.1 will be generated in the corresponding directory.

Then set the environment variable. Because there is more than one compiler on the Linux machine, in order to avoid environment variable conflicts, it is best to create a new account, such as arm-linux-gcc, and then find the .bash _ profile file in the corresponding account directory, set the environment variable, edit .bash _ profile, and add a path on the last line (vi opens the text file, press I for insert to modify the text file, and then Esc exits the insert mode. Then shift zz means to save the exit file, and the detailed command description can be found on the Internet.):

Export PATH=/usr/local/arm/2.95.3/bin:$PATH

You can use echo $PATH to see if the environment variable is set successfully:

5.2.3 compile and run the program

After editing the code file and establishing the cross-compilation environment, we begin to compile the code to generate the executable program, and transplant it to the arm board to run the program.

In the terminal of the Linux system, type arm-linux-gcc/arm-linux-g++ to compile the Candlestick + file. For example, we compiled the simplest CppHelloWorld.cpp file we wrote earlier:

Arm-linux-g++ CppHelloWorld.cpp-o CppHello

An application CppHello that can run on the arm-linux system is then generated under the corresponding directory.

Then the executable file is transferred from the Linux file system network to the arm-linux file system through the SSH service and the FTP service (two small softwares SSH Secure and LeapFTP are used here, and the functions of the software are briefly introduced later).

Then remotely log in to the arm-linux system development board on the Windows machine and control the program to run

Note: you need to tell the system that this file is executable through chmod + x CppHello before running the program through. / CppHello.

We can see the result of the program running: a line of "Hello World" is printed on the screen.

5.3 introduction of some commonly used software

In some of the operations described above, some software is used for file transfer, which is briefly introduced here.

LeapFtp

LeapFtp

A file transfer software based on Ftp protocol. In general, we open the Ftp service on the arm-linux machine, and then we can transfer files between the Windows machine and the arm-linux machine.

SSH Secure File Transfer Client

A file transfer software based on SSH protocol, which can realize the function of FTP. Although the Linux machine and the Windows machine can exchange files through a shared directory, because the shared directory is actually equivalent to a virtual external device of the Linux machine, the system will reread it every time the code is written and saved, causing a little trouble in the operation, so it is recommended to use SSH for file transfer.

SSH Secure Shell Client

A SSH-based remote login software, can achieve telnet function. Because Fedora turns off the telnet function by default, it uses the more secure SSH protocol to implement the related functions of telnet.

The main network architecture between the three systems is as follows:

Note:

1. If the ftp and telnet of the arm-linux system are not connected, generally speaking, the corresponding service is not enabled by arm-linux by default, or the default ip and windows machines are not in the same network segment. You can connect the arm board to the computer through the serial cable, then open the hyperterminal, enter the command vsftpd& to start the ftp service, enter the command telnetd to start the telnet service, and ifconfig eth0 192.168.1.16 set the IP to the same network segment.

two。 If the SSH connection of the Linux system is not connected, in general, it is the Linux system that turns on the firewall of SSH, so you only need to set the firewall in the Linux system and turn off the firewall for SSH. [System]-- [Administration]-- [Firewall], then check the omnipotent SSH.

There are other software, such as team collaboration, need to use SVN for code management; and remote desktop VNC Viewer, can be used for remote desktop control (but the effect is not very good, desktop display delay seems to be serious), and so on.

5.4 develop arm-linux window programs

5.4.1 Establishment of Qt cross-compilation environment

Create a new directory / root/yizhi on the Linux system, and then copy the compiled arm-QT library to this directory.

Then extract the above six tar.gz files to the / root/yizhi directory.

When compiling Qt under arm-linux, it also involves the setting of environment variables, so we'd better create a new account specifically for compiling arm-Qt programs.

For example, add the user zsm to the Linux system terminal, then go to / home/zsm, modify the .bash _ profile, and set the environment variable:

In the command terminal, ls-a shows all hidden files to find .bash _ profile, enter:

Gedit .bash _ profile &

After opening this file with geidt, add the following environment variable settings at the end:

Export PATH=/root/yizhi/qtopia-free-2.2.0/qtopia/bin:/root/yizhi/qtopia-free-2.2.0/tmake/bin:/root/yizhi/qtopia-free-2.2.0/qt2/bin:/usr/local/arm/2.95.3/bin:$PATH

Export QTDIR=/root/yizhi/qtopia-free-2.2.0/qt2

Export QTEDIR=/root/yizhi/qtopia-free-2.2.0/qtopia/

Export LD_LIBRARY_PATH=$QTDIR/lib:$QPEDIR/lib:$LD_LIBRARY_PATH

Export CC=/usr/local/arm/2.95.3/bin/arm-linux-gcc

Export TMAKEDIR=/root/yizhi/qtopia-free-2.2.0/tmake

Export TMAKEPATH=$TMAKEDIR/lib/qws/linux-arm-g++

After setting up, it is best to log in to this account again, and then type echo $PATH in the terminal to verify whether the environment variable is set successfully:

If the above output appears, it means that the environment variable for the Qt cross-compilation environment on the arm-linux platform has been set successfully. Next, you can develop Qt programs.

5.4.2 compile and generate an executable form program

A single-file project QtHello has been written in Section 3.2, and a QtHello.cpp file has been generated in the project's src directory, and then all we have to do is compile it using the Qt compiler under arm-linux.

Compiling a Qt forms project is a little more troublesome than compiling an ordinary console project. You need to write your own makefile to establish the compilation rules. The makefile for compiling QtHello.cpp as above has the following template:

# Makefile for building hello# Generated by tmake at 20:58 2011/04/14# Project: hello# Template: app#### Compiler Tools and optionsCC = arm-linux-gccCXX = arm-linux-g++CFLAGS =-pipe-Wall-W-O2-DNO_DEBUGCXXFLAGS=-pipe-DQWS-fno-exceptions-fno-rtti-Wall-W-O2-DNO_DEBUGINCPATH =-I. -I $(QTDIR) / includeLINK = arm-linux-gccLFLAGS = LIBS = $(SUBLIBS)-L $(QTDIR) / lib-lm-lqteMOC = $(QTDIR) / bin/mocUIC = $(QTDIR) / bin/uicTAR = tar-cfGZIP = gzip-9f# FilesTARGET = QtHelloHEADERS = $(TARGET). HSOURCES = $(TARGET). CppOBJECTS = $(TARGET). ODIST = INTERFACE_DECL_PATH = .# Implicit rules.SUFFIXES: .CPP .cxx .cc. C. c.cpp .o: $(CXX)-c $(CXXFLAGS) $(INCPATH)-o $@ $

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report