Cross-compilation tool chain for Linux subsystem under Windows (arm-linux-gcc)

Cross-compilation tool chain for Linux subsystem under Windows (arm-linux-gcc)

1. Download arm-linux-gcc-4.3.2.tar.bz2, then unzip it to the /usr/local/ directory, use the command:

  sudo tar -jxvf arm-linux-gcc-4.3.2.tar.bz2 -C / 

Installed to the /usr/local/arm directory by default

2. Then give full permissions to the /usr/local/arm/ folder

sudo chmod 777 /usr/local/arm

Three, then use vim to open the /etc/profile file

sudo vi /etc/profile 

Add the following at the end

export PATH=/usr/local/arm/4.3.2/bin/:$PATH

After adding, execute

source /etc/profile

Make the configuration effective

5. Then execute arm-linux-gcc -v to check the cross tool version, but there will be problems as follows
arm-linux-gnueabihf-gcc: cannot execute binary file: Exec format error.
After finding solutions in various forums, some say yes ubuntu64-bit system, and arm-linux-gcc is a 32-bit package, so the 32-bit package installed under ubunt is compatible with arm-linux-gcc,
such

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386
sudo apt-get install lib32ncurses5 ​lib32ncurses5-dev
sudo apt-get install lib32z1

Nothing works well , there will still be a problem of “ cannot execute binary file: Exec format error” .
At the moment I was about to give up, I found a post
with a source link: https://www.cnblogs.com/JiuHuan/p/10073632.html
to show respect for intellectual property rights.

solution

Check the program export table through readelf -a arm-linux-gcc. The
readelf command reports an error: Not an ELF file-it has the wrong magic bytes at the start
. The source of the problem is initially determined. The subsystem does not support native Linux file headers.
The solution is as follows:
add xxx format file header support

sudo apt update
sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic
'\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'

Execute arm-linux-gcc -v again, finally it is normal

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41782149/article/details/104342138