Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross compiling for arm from x86

I am trying to insert a .ko kernel module into the linux running in arm processor. I built a .ko file in my desk PC which is a x86 one. How do I cross compile it to arm specs. I am new to this field.

Thanks in advance

like image 575
Deeraj Soman Avatar asked Feb 08 '13 04:02

Deeraj Soman


People also ask

Can I compile for x86 with arm?

No. Its because cross compiler(including clang) can generate binaries from host gcc for a target. There is no compiler which can generate x86 instructions from arm.

How do you cross-compile arms with GCC?

Save this answer. Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation. This brings in the complete cross-compile environment, including binutils. On Ubuntu 13.10 you get gcc-4.7 for 'gnueabi' and gcc-4.8 for 'gnueabihf'.

Can GCC compile to arm?

Use GCC to cross-compile binaries for different architectures from a single build machine. If you're a developer creating binary packages, like an RPM, DEB, Flatpak, or Snap, you have to compile code for a variety of different target platforms. Typical targets include 32-bit and 64-bit x86 and ARM.


1 Answers

For that you need to download the ARM compilers first. I suggest you download the compiler from http://www.linaro.org/downloads/ then set the CROSS_COMPILE environment variable to arm-linux-gcc.

set the bin directory path in PATH variable.You can do it by export PATH=$PATH:/path/to/arm/binaries/

Finally compile the code then run in ARM.

use file <filename> whether it is ARM executable or not.

like image 103
Jeyaram Avatar answered Oct 29 '22 09:10

Jeyaram