Linux arm cross compiler gcc

Technical Knowledge Overview

In this blog I am explaining Different Technical Knowledge If you have any doubts about any thing Just post me i will try to clear the doubts. Thanks in Advance.

Thursday, 24 March 2016

Install the ARM cross compiler toolchain on your Linux Ubuntu PC

This article illustrates how to install on a Ubuntu Linux PC the complete toolchain to cross compile the Linux Kernel, the Linux device drivers, the Linux applications and the boot loader like as AT91Bootstrap and its derivates like AcmeBoot and AriaBoot.

Install the Cross Compilers, utilities, etc.

$ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross $ sudo apt-get install binutils-arm-linux-gnueabi $ sudo apt-get install libncurses5-dev 
$ sudo apt-get install gcc-arm-linux-gnueabi $ sudo apt-get install g++-arm-linux-gnueabi 
$ sudo apt-get install gcc-arm-linux-gnueabihf $ sudo apt-get install g++-arm-linux-gnueabihf 

Now you are ready to cross-compile on your PC all the source available for the Acme Boards based on Atmel MPUs.

Try the cross C compiler

#include "stdio.h" int main(void)  printf("Hello world !\n"); return 0; >
~$ arm-linux-gnueabi-gcc hello.c -o hello 

As you can see we are using the ARM version of gcc just installed on your PC. It will generate an executable file for your Linux board.

~$ scp hello root@[your_board_ip]:/root 

Try the cross C++ compiler

#include "iostream" using namespace std; int main(int argc, char *argv[])  cout  <"Hello world !" < endl; return 0; >
~$ arm-linux-gnueabi-g++ hello.cc -o hello 

As you can see we are using the ARM version of gcc just installed on your PC. It will generate an executable file for your Linux board.

~$ scp hello root@[your_board_ip]:/root 

ONE MORE METHOD IS BELLOW ID FIRST ONE NOT WORKED THEN JUST GO FOR SECOND METHOD:

Cross compilation for ARM based Linux systems

This steps are tested on Ubuntu Linux 12.04, but should work for other Linux distributions. I case of other distributions package names and names of cross compilation tools may differ. There are several popular EABI versions that are used on ARM platform. This tutorial is written for gnueabi and gnueabihf, but other variants should work with minimal changes.

Prerequisites

Cross compilation tools for ARM: gcc, libstc++, etc. Depending on target platform you need to choose gnueabi or gnueabihf tools. Install command for gnueabi:

sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install gcc-arm-linux-gnueabihf

[optional] ffmpeg or libav development packages for armeabi(hf): libavcodec-dev, libavformat-dev, libswscale-dev;

Getting OpenCV Source Code

You can use the latest stable OpenCV version available in sourceforge or you can grab the latest snapshot from our Git repository.

Getting the Latest Stable OpenCV Version

Getting the Cutting-edge OpenCV from the Git Repository

cd ~/ git clone https://github.com/Itseez/opencv.git

Building OpenCV

cmake [] -DCMAKE_TOOLCHAIN_FILE=source directory>/platforms/linux/arm-gnueabi.toolchain.cmake source directory>

Toolchain uses gnueabihf EABI convention by default. Add -DSOFTFP=ON cmake argument to switch on softfp compiler.

cmake [] -DSOFTFP=ON -DCMAKE_TOOLCHAIN_FILE=source directory>/platforms/linux/arm-gnueabi.toolchain.cmake source directory>
cd ~/opencv/platforms/linux mkdir -p build_hardfp cd build_hardfp cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..

Optionally you can strip symbols info from the created library via install/strip make target. This option produces smaller binary (~ twice smaller) but makes further debugging harder.

Enable hardware optimizations

Depending on target platform architecture different instruction sets can be used. By default compiler generates code for armv5l without VFPv3 and NEON extensions. Add -DENABLE_VFPV3=ON to cmake command line to enable code generation for VFPv3 and -DENABLE_NEON=ON for using NEON SIMD extensions.

TBB is supported on multi core ARM SoCs also. Add -DWITH_TBB=ON and -DBUILD_TBB=ON to enable it. Cmake scripts download TBB sources from official project site http://threadingbuildingblocks.org/ and build it.

How do I cross-compile the kernel on a Ubuntu host?

Preparation

sudo apt-get install git ncurses-dev make gcc-arm-linux-gnueabi 
  • git is the version control system used by the Linux kernel team.
  • ncurses is a library for build console menus. It is necessary for menuconfig .
  • make runs the compilation for us.
  • gcc-arm-linux-gnueabi is the cross-compiler.
git clone https://github.com/raspberrypi/linux raspberrypi-linux cd raspberrypi-linux 

Compilation

cp arch/arm/configs/bcmrpi_cutdown_defconfig .config 
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig 
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig 
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-gcc -k 

References

Источник

Compiling native GCC for arm using cross-compiler

Cross-compiling is process of compiling program for different system than one it is being compiled on. It is typically done to target embedded systems or compile for a different architecture than host system. process of cross-compiling for ARM is essential when targeting embedded systems that are commonly found in Internet of Things (IoT) devices. In this article, we will discuss how to compile native GCC for ARM using a cross-compiler.

What is ARM?

ARM is a type of processor architecture that is widely used in embedded systems. It is a type of Reduced Instruction Set Computer (RISC) architecture that is used in a variety of devices, such as smartphones, tablets, and IoT devices. ARM processors are known for their low power consumption, high efficiency, and scalability. They are designed to be used in low-power and low-cost devices, making them ideal for use in embedded systems.

What is a Cross-compiler?

A cross-compiler is a compiler that is used to compile code for a different system than one it is being compiled on. It is typically used to compile code for embedded systems or to target a different architecture than host system. cross-compiler generates code that is optimized for target architecture and can be executed on target system.

Cross-compiling Native GCC for ARM

GCC is a widely used open-source compiler that supports multiple programming languages. It is available for multiple architectures, including ARM. In this section, we will discuss how to cross-compile native GCC for ARM using a cross-compiler.

Step 1: Installing cross-compiler

To cross-compile native GCC for ARM, we need to first install cross-compiler. There are multiple cross-compilers available, such as Linaro, Yocto, and Buildroot. In this article, we will be using Linaro as cross-compiler.

To install Linaro cross-compiler, we need to download Linaro toolchain from Linaro website. Once downloaded, we need to extract toolchain to a directory of our choice.

Step 2: Configuring cross-compiler

Once cross-compiler is installed, we need to configure it to compile code for ARM. To do this, we need to set PATH variable to include directory where cross-compiler is installed. We can do this by adding following line to .bashrc file −

export PATH=$PATH:/path/to/cross-compiler/bin

Next, we need to set environment variables to point to cross-compiler. We can do this by running following command −

export CC=arm-linux-gnueabihf-gcc

This sets CC environment variable to name of cross-compiler.

Step 3: Compiling native GCC for ARM

With cross-compiler configured, we can now compile native GCC for ARM. To do this, we need to download GCC source code and extract it to a directory of our choice. We can then configure GCC for cross-compilation by running following command −

./configure --target=arm-linux-gnueabihf --prefix=/path/to/install/gcc --enable-languages=c,c++

This command configures GCC to cross-compile for ARM and installs it to specified directory. We can then compile GCC by running make command.

Once GCC is compiled, we can test it by cross-compiling a sample program for ARM. We can do this by creating a simple «hello world» program in C and compiling it using cross-compiler. program can be written as follows −

#include int main() < printf("Hello, world!
"); return 0; >

We can then compile program for ARM by running following command −

arm-linux-gnueabihf-gcc -o hello hello.c

This will generate an ARM executable that we can run on an ARM device.

Cross-compiling native GCC for ARM using a cross-compiler is an essential step when developing applications for embedded systems. This process allows developers to create optimized and efficient code for ARM devices, which are commonly used in IoT devices, smartphones, tablets, and other low-cost and low-power devices.

The process of cross-compiling native GCC for ARM can be broken down into three main steps − installing cross-compiler, configuring cross-compiler, and compiling native GCC for ARM. Each of these steps is critical to successfully generate ARM executables that can be run on an ARM device.

When installing cross-compiler, it is essential to choose a reliable and widely used toolchain, such as Linaro, Yocto, or Buildroot. cross-compiler should be downloaded and installed in a directory that can be easily accessed, and PATH variable should be updated to include directory where cross-compiler is installed.

Configuring cross-compiler involves setting environment variables, such as CC variable, to point to name of cross-compiler. This step ensures that cross-compiler is used to compile code for ARM.

The final step of process is compiling native GCC for ARM. This is done by downloading GCC source code, configuring it for cross-compilation, and compiling it using make command. Once native GCC is compiled, it can be used to compile C and C++ code for ARM.

Conclusion

Cross-compiling native GCC for ARM is a necessary step when targeting embedded systems. By using a cross-compiler, we can generate optimized code for ARM architecture that can be executed on an ARM device. In this article, we discussed steps involved in cross-compiling native GCC for ARM using Linaro cross-compiler. By following these steps, developers can easily generate ARM executables that can be used in a variety of embedded systems.

Источник

Читайте также:  Поиск файлов созданных linux
Оцените статью
Adblock
detector