A detailed tutorial on a cross-compiled Raspberry Pi on a Linux host

Source: Internet
Author: User
Tags filezilla

The Linux host os:ubuntu14.04 64-bit and runs on WMware workstation 10.

Raspberry Pi Version: Raspberry Pi 2 Type B.

Raspberry Pi OS: The Raspbian-jessie under the official website.

1. Why cross-compiling is required

Compiling a. C source file directly on Ubuntu can be compiled with the system's own GCC compiler test.c

GCC Test.c-o Test

Then execute the resulting binary file

./test

Cross-compiling is the process of compiling the compilation on a Linux PC (or other host) and then copying the binaries to the Raspberry Pi (or other platform) for execution.

Personal understanding using cross-compiling is primarily fast and convenient for debug, if compiling one or two source files may be no different between PC and Raspberry Pi, but if compiling kernel speed gap is obvious.

About the process of compiling reference: http://lxwei.github.io/posts/262.html

2. What cross-compilation tool to use

The cross-compilation tool is selected for the platform that executes the binaries and has a dedicated cross-compilation tool for the Raspberry Pi: https://github.com/raspberrypi/tools, select Branch:master version, right clone or Download, click Download Zip to download.

can also be installed directly online:

sudo Install build-essential Gitgit clone git://github.com/raspberrypi/tools.git

Cross-compiling tools for other platforms please Google yourself.

3. Install the cross-compilation tool

3.1 Decompression

Download the completed file for Tools-master.zip, you can directly right-click Extract decompression, you can also unzip decompression to the new RPI folder,-D is used to specify the path to./rpi

mkdir rpiunzip-d./rpi tools-master.zip

Under the RPI file, there are 5 folders under the tools/arm-bcm2708 folder (different versions may differ slightly):

For 32-bit Ubuntu, use Gcc-linaro-arm-linux-gnueabihf-raspbian, For 64-bit use gcc-linaro-arm-linux-gnueabihf-raspbian-x64. Select the cross-compilation tool on the 64-bit.

3.2 Adding environment variables

You need to add environment variables to use the cross-compilation tool. The environment variable is simply the path of the specified program, so that the program can run directly at the terminal. For example, executing the LS instruction does not require/BIN/LS because the path has been added to the environment variable path PATH.

To view environment variables, you can use:

Echo $PATH

For environment variables, refer to http://opsmysql.blog.51cto.com/2238445/665990

Add the cross-compilation tool to the environment variable, you can add it directly at the end of the/etc/profile file

#rpi Cross compile Pathexport path= $PATH: $HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/ Bin

Restart causes environment variables to take effect immediately

3.3 Testing

Test whether the installation is successful, follow the online method to type in the terminal

Arm-linux-gnueabihf-gcc-v

The error is as follows

After repeatedly confirming that the environment variable path is not a problem, it is found that there is a ARM-LINUX-GNUEABIHF-GCC text file under Gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin, The content is arm-linux-gnueabihf-gcc-4.8.3, and this file is an executable file. This can be done for compatibility with the version update.

The terminal executes the following command

Arm-linux-gnueabihf-gcc-4.8.3-v

You can see that the installation is OK

4 using cross-compilation to build an executable file

For a single simple source file, a binary file can be generated by invoking the cross-compilation tool directly with the instruction, and for complex multi-source files It is necessary to write makefile and then make instructions to compile

Here, compile hellowd.c with the command line to generate an executable file for the Raspberry Pi Hellowd

HELLOWD.C as follows

#include <stdio.h>int main () {printf ("Hello,world linux\n");}

Specify to the HELLOWD.C path, and compile, the result error is as follows

According to the error message, view the path/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/libc.so.6

Found this is a text file, content libc-2.13.so based on previous experience, libc.so.6 should be point to libc-2.13.so and the compiler uses libc.so.6 by default but should actually use libc-2.13.so, Just rename the libc-2.13.so to Libc.so.6 (back up the libc.so.6 text file first).

Compile again as follows

As above, just modify the name of the ld-2.13.so file specified in ld-linux-armhf.so.3 to Ld-linux-armhf.so.3

Compile again no error

You can see the generated executable file under the source file path, note that you need to copy to the Raspberry Pi to perform

5. Executing executable files on Raspberry Pi

5.1 Installing FileZilla

Due to conditions, Raspberry Pi can not be networked, nor can use a USB flash drive, only Ubuntu host can surf the Internet. Before attempting to install VSFTPD in Ubuntu host, Raspberry Pi FTP host IP to transfer files, The results revealed that the Raspberry Pi system did not have FTP instructions installed. Finally, the FileZilla software is used to implement Ubuntu and Raspberry Pi file transfer.

I am using the. deb installation and need to manually install several dependent libraries, Ubuntu14.04 64-bit FileZilla links are as follows https://pkgs.org/ubuntu-14.04/ubuntu-universe-amd64/ filezilla_3.7.3-1ubuntu1_amd64.deb/download/

Conditions allow to be installed directly online, please Google

To see if Ubuntu is a 32-bit or 64-bit command

Uname-a

If x86_64 appears to be AMD64 bit, the i686 (other system may i386) is 32-bit

My 64-bit Ubuntu is as follows

5.2 Copy hellowd executable file

The Raspberry Pi and Ubuntu pc are connected to the switch (or router) via a network cable respectively, if the Raspberry Pi external LCD screen can be operated directly on the Raspberry Pi, otherwise it can be operated remotely via Putty Software on the PC, however Putty needs to know the IP address of the Raspberry Pi

The router can be used in the router address of the browser to query the IP of the Raspberry Pi, with a display can be on the Raspberry Pi command line to view the IP

Ifconfig

As for how to view the Raspberry Pi IP without a router without a display, this is pending google

Raspberry Pi and PC Direct connect reference https://embeddedday.com/projects/raspberry-pi/basics/direct-connection-to-pc/

Get to the IP of the Raspberry Pi, for example my is 192.168.2.46 can transfer files to Raspberry Pi with FileZilla

Host to fill Raspberry Pi ip:192.168.2.46

Username:pi

Password:raspberry (default password)

Port:22

Click Quickconnect to connect successfully

Right-hellowd file, add files to queue added to the transport queue

The lower transmission queue right-click Process Queue processing queues to complete the transfer. Refresh can see right Raspberry Pi already has hellowd file

5.3 Executive Hellowd

The Raspberry Pi external display can be directly CD to the Hellowd path, and then./hellowd Execution

can also be executed on the PC via the Putty login Raspberry Pi

The default login pi password raspberry password will not be displayed, after entering the direct return

You need to change the permissions so that the passwd can be executed by the Raspberry Pi, performing the following

You can see that the cross-compilation succeeds as expected by the program

Reference documents

http://blog.csdn.net/xukai871105/article/details/24932611

Http://www.cnblogs.com/xieyajie/p/4699724.html

http://opsmysql.blog.51cto.com/2238445/665990

A detailed tutorial on a cross-compiled Raspberry Pi on a Linux host

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.