Implementing cross-compilation on MacOS

Source: Internet
Author: User
Tags bz2

In the embedded development process, the storage space and computing capacity of the device is usually relatively low, this time, such as to compile a Linux kernel, embedded devices are not competent, so it is necessary to achieve cross-compilation. By cross-compiling, we are able to compile executable programs on our PC that can be used on embedded devices.

Next, I'll walk you through how to implement cross-compilation of Raspberry Pi (arm) on Mac OS.

One. Create a new disk image

MAC OS file system default is case insensitive, and cross-compilation toolchain is case-sensitive file system, so we can not directly install the tool chain in the original file system, but need to create a new case sensitive disk impression for the installation tool chain.

This is not a difficult feature to implement, and can be achieved using disk utility with the system's own disks. Open Disk Utility, then file > New > Blank disk image, and then in the pop-up window set the name Arm-x (for easy follow-up), with a size of at least 500M, in the form of a Mac OS extension (case-sensitive, journaled) image (for example).

Two. Download the tool chain that has been compiled

Download the compiled arm GNU Linux toolchain from the link below:

https://github.com/downloads/UnhandledException/ARMx/ARMx-2009q3-67.tar.bz2

If you want to compile your own steps and understand the specific elements in the toolchain, you can take a look at the following document:

Https://github.com/UnhandledException/ARMx/wiki/Sourcery-G---lite-for-arm-gnu-linux-(2009q3-67)-for-mac-os-x

three. Unzip the tool chain to the magnetic disk image

In the directory where the terminal enters the compressed package, execute the following instructions:

(The new disk image is mounted by default, if it is not mounted, please manually mount it first)

Tar-zx-c/volumes/arm-x/--strip-components 1-f armx-2009q3-67.tar.bz2

Four. Using the tool chain

Now we can use the tool chain directly, for example, I wrote a hello.c program, and now I can compile the program directly using the Toolchain.

In terminal execution:

/VOLUMES/ARM-X/BIN/ARM-NONE-LINUX-GNUEABI-GCC Hello.c-o Hello

You can get an executable program called Hello. This program is not operational under Mac and needs to be run on the ARM processor's device.

Of course, if you would like to enter a large string of paths to call the ARM-NONE-LINUX-GNUEABI-GCC program trouble, you can add the/volumes/arm-x/bin directory to the path, so that it can be used as a system command. (There are many ways to add environment variables, it is recommended to add the path to the ~/.profile file, the specific operation of Baidu you know)

Five. Upload the Hello program to the Raspberry Pi.

If you know how to upload the file to the Raspberry Pi, please upload it directly. If not, I'm here to offer two ways:

1. Using SFTP: This method does not need to be set separately, can upload files directly to the Raspberry Pi, but each change will need to be re-uploaded.

Steps:

SFTP [email protected] (IP address is changed according to your address)

Then enter the password raspberry

Put/local file path/upload directory to Raspberry Pi

(Example: Put/users/icool/desktop/hello. )

2. Using NFS: This method needs to be configured first, but it is easy to use when configured. You can map the files on your Raspberry Pi directly to your Mac so that you can't change them on your Mac without uploading them.

Refer to this document for specific steps:

Http://server.zdnet.com.cn/server/2007/0831/482007.shtml

Six. Perform upload on Raspberry Pi program

SSH connect the Raspberry Pi (or any method, log on to the Raspberry Pi).

Then enter the directory where the Hello program is located and execute:

./hello

The results are as follows:

Seven. Testing floating-point programs

You can see from the previous step that the cross-compiled Hello,world program can run properly on the Raspberry Pi, and check to see if the floating-point program works as well.

Write a simple floating-point program first:

Test results:

Implementing cross-compilation on MacOS

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.