How to use Eclipse for embedded Linux development
Zenghonghan, senior lecturer of Huaqing Vision Embedded College.
How to use Eclipse to develop embedded Linux the programmers who develop in Windows environments often complain that they don't have a good integrated development environment when they go to the Linux platform. Compared with some of the development software commonly used under Windows, Linux comes with some development environments that are not easy to use, friendly, or functional in terms of interface and operation. In fact, we can find the easy-to-operate, powerful development environment in the open source community. Here is an introduction to the development platform eclipse, which can be run on Linux, with interfaces and features similar to similar software on Windows.
Eclipse is a well-known cross-platform integrated development Environment (IDE) that was originally developed by IBM as an alternative to commercial software for the next generation development environment of visual age for Jave. In 2001, IBM contributed eclipse to the open source community, now managed by the Eclipse Foundation. In July 2005, Eclipse stable version 3.1.0 was released, and the latest stable release is now 3.4.
Eclipse itself is only a framework platform, initially primarily for the Java language development. But the support of many plugins makes it possible for Eclipse to develop other languages, such as C + +, C #, Perl, COBOL, and so on. The CDT (c/s + + Development Toolkit) is a plug-in that supports C + + development. Many software developers have also launched their own integrated development environment with Eclipse as the framework. Because the Eclipse platform is implemented in Java, the runtime requires the support of the JRE (Java Runtime Environment). Here's an example of how to use ECLIPSE+CDT on Linux for the development of embedded Linux applications using Ubuntu (one of the Linux distributions).
First, install the software
There are two ways to install software under Ubuntu: Use Apt-get to come from an installation or manual installation. Users use automatic installation is very convenient, suitable for beginners. However, the installation process is too dependent on the connectivity of the resource site and may take too much time. Here we recommend the manual installation method, the time spent is relatively short.
1. Installing the JDK
The JDK (Java Development Kit) is a Java development package that contains the JRE required to run eclipse. The GNU version of the JRE installed by default is inefficient, so we need to install Sun's JRE. First download the installation package Jdk-6u7-linux-i586.bin from the Sun's website (http://java.sun.com/javase/downloads/index.jsp) and install it as follows:
# mkdir-p/opt/java
#./jdk-6u7-linux-i586.bin//Execute self-extracting file, generate directory
# MV Jdk1.6.0_07/opt/java//move directory to/opt/java
# Cd/opt/java
# ln-s jdk1.6.0_07 JDK
# MV/ETC/ALTERNATIVES/JAVA/ETC/ALTERNATIVES/JAVA.GNU
# ln-s/opt/java/jdk/bin/java/etc/alternatives/java
# Export JAVA_HOME=/OPT/JAVA/JDK//SET environment variable
2. Installing Eclipse and CDT
Download the installation package eclipse-sdk-3.4-linux-gtk.tar.gz and Cdt-master-5.0.0.zip from the Eclipse website (http://www.eclipse.org/)
# cd/opt
# tar ZXVF eclipse-sdk-3.4-linux-gtk.tar.gz//unzip generate eclipse directory
# Export Path=/opt/eclipse: $PATH
# mkdir-p/OPT/CDT
# CD/OPT/CDT
# Unzip Cdt-master-5.0.0.zip
# cp-r plugins/*/opt/eclipse/plugins/
# cp-r features/*/opt/eclipse/features/
Ii. creation of C + + projects
Let's say we've installed the arm crossover toolchain on Linux, and here's how to create, cross-compile, and debug C + + projects. For a more intuitive explanation, we intercepted the relevant images:
After entering the Eclipse installation path, run eclipse
Eclipse Runtime Interface
Create a C project
Using the default Linux gcc toolchain
Go to C + + interface
Add source code file 1
Add source code file 2
Edit Code
Set project properties, specify cross toolchain 1
Set project properties, specify cross toolchain 2
Set project properties, specify cross toolchain 3
Compiling the project
Generated Arm platform executable code
Configuring Debugging Options
Set debugger and GDB debugger options
Set the connection type to TCP, the IP address of the target board, and the debug port number. Port number specified arbitrarily, usually greater than 1024 (avoid conflicts with the port number used by the system)
Run the program on the Development Board, as shown in the format: Gdbserver is a cross-debug helper; The 192.168.0.150 is the IP address of the host, 1234 is the debug port number, and the port number set in the Eclipse Debug option is the same
Click Debug to enter the Debug interface
Execute to Breakpoint
The debugging interface and operations of Eclipse are similar to those developed under Windows, and it is believed that this step has made it easy for you to develop your application.
Required development tools and environment
- Virtual Machine Linux:fedora 9
- Cross-compilation tool: ARM-LINUX-GCC-3.4.1.TAR.BZ2
- Integrated development tools: Eclipse (comes with Linux installation package, installed when installing Linux)
Installing the arm Cross compiler
1. Install. In fact, it is very simple to extract the downloaded arm-linux-gcc-3.4.1.tar.bz2 to the Linux root directory (because the extract already contains the/usr/local directory, so to extract to the root directory), such as the following command:
tar -jxvf arm-linux-gcc-3.4.1.tar.bz2 -C /
|
The extracted directory such as:
The extracted directory/USR/LOCAL/ARM/3.4.1/
2. Set environment variables. is to set the path of the cross compiler to the system environment variable.
View existing environment variables, as shown in:
If you only want to temporarily add the cross-compiler environment variable (note: The temporarily added system restarts or logs out after it is not), simply enter the following command at the command line:
export PATH=$PATH:/usr/local/arm/3.4.1/bin
|
Added environment variables such as: (more than one/usr/local/arm/3.4.1/bin)
If you want this environment variable to be permanently added to the environment variable of the system, then you simply add this command to the last line of the/ROOT/.BASHRC file (the file is a hidden file, you can click the View menu in the file browser, tick show hidden files to see)
3. Test the built-in cross-compilation environment. Create a new C program, file name: TEST.c, as follows:
#include <stdio.h>
int main(void) { printf("Hellow world!\n"); return 0; }
|
To cross-compile as follows:
arm-linux-gcc -o test test.c
|
Download the cross-compiled target file test to the arm Development Board and run it as follows:
The output is: Hellow world!
Develop embedded applications with integrated development tool eclipse
Double-click the Eclipse icon to start eclipse
To set up an Eclipse workspace, choose a directory, click OK
The main interface after startup
Start a new Application project
Select Create a new C project and click Next
Give the project a name, here I call Test_app; then select the project type, I chose a hellow World C project template, click Next
Fill in the author, copyright and other information, click Next
No choice, click Finish.
Click Yes
Construction of a new project
Expand the left source directory and double-click to open the main function. Here is just the output of a "Hello world!!!", you can do some other complex applications
Click on the Project menu to remove the tick of build automatically, as checked, the project will be compiled automatically every time you modify a local.
Open the Properties dialog box for the project to set the compilation options
Our application eventually runs on the embedded arm, which is going to change GCC to the ARM-LINUX-GCC compiler, if you want to install the ARM-LINUX-GCC on your development host first
C connector is also changed to ARM-LINUX-GCC
The libraries here is to set the library file used in your application, such as the application of the thread class, then add Pthread this library, the following will add the path of this library. If the application doesn't use any library files, it's out of the control.
Select the project name on the left, right-click on the popup menu and select Build project to compile the project
After compiling the project, the target file is in the debug directory
Conclusion
The establishment of cross-compilation environment is the first step in the development of embedded programs, there are many compiler version, here is the introduction of more than one. And Eclipse is the most convenient integrated development tool I think the development of embedded applications, he not only makes the whole project clearly visible, more importantly, he does not need you to write complex makefile files for the whole project, he will automatically generate makefile for you.
Install ARM Cross-compilation environment on Ubuntu ARM-LINUX-GCC
First download arm-linux-gcc-4.3.2.tgz, this is not much to say, focus on how to install. Copy the arm-linux-gcc-4.3.2.tgz file to Ubuntu's home folder, create a new terminal in Ubuntu, run as root, and enter the following command to install the cross-compiler:
#tar ZXVF arm-linux-gcc-4.3.2.tgz
After decompression will produce USR folder, the directory under the Usr/local/arm arm folder copied to the file system usr/local directory, command for
#mv Usr/local/arm usr/local
Then add the cross-compiler path to the system environment variable,
Execute in Terminal:
Gedit/etc/profile
Add the following four lines to the file:
Export Path=/usr/local/arm/4.3.2/bin: $PATH
Export toolchain=/usr/local/arm/4.3.2
Export tb_cc_prefix=arm-linux-
Export pkg_config_prefix= $TOOLCHAIN/arm-none-linux-gnueabi
How to use Eclipse for embedded Linux development