Ubuntu builds a cross-compilation environment
say something
Why do you need to cross compile
If you want to do equipment, embedded and other work, cross-compilation is essential.
The memory of the embedded device is too small to even start the compilation. You have to compile it on the host, and then put the compiled program into the embedded device.
Introduction to Cross Compilation Environment
Architecture-Vendor-Platform Differentiator
Example:i386-pc-linux2.4.3
Architecture-platform-compiler distinguishes the compilation environment
For example:arm-linux-gcc
Arm cross-compilation environment setup
We build the arm-linux-gcc compilation environment:
First, Ctrl+Alt+T pops up the terminal, and use the following command to install arm-linux-gcc:
Method 1 (not recommended, often errors):
sudo apt-get install gcc-arm-linux-gnueabihf
Use the following command to install arm-linux-g++:
sudo apt-get install g++-arm-linux-gnueabihf
Method 2 (recommended):
1. Download and decompress
Download and arm-linux-gcc-4.4.3.tar.gz
decompress/home/darui/Desktop/arm-linux-gcc
Second, configure the system environment variables
sudo gedit /etc/profile
Add the last line
export PATH=$PATH:/home/darui/Desktop/arm-linux-gcc/opt/FriendlyARM/toolschain/4.4.3/bin
Save to take effect
source /etc/profile
Third, check
arm-linux-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1)
Fourth, cross-compile
Introduce environment variables
source /etc/profile
Install the library
sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1
compile
arm-linux-gcc -o new.c pp
success
Mips cross-compilation environment setup
1. Download and decompress
OpenWrt SDK for C/C++ for Linux (it is recommended to use it under 64-bit)
https://docs.labs.mediatek.com/resource/linkit-smart-7688/zh_cn/downloads
decompress
tar -jxvf OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
2. Configure environment variables
gedit ~/.bashrc
Guide the unzipped folder ( note: to the fourth-level folder )
export PATH=$PATH:/home/darui/Desktop/mips-linux-gcc/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin
keep
source ~/.bashrc
( Note: bashrc is the user's environment variable, add the bashrc variable under root, ordinary users do not add variables /etc/profile is the overall environment variable )
3. Cross compiling
Powerpc cross-compilation environment construction
1. Install apt manager
sudo add-apt-repository univers
sudo apt update
sudo apt install synaptic
2. Download environment
sudo synaptic
After selecting, click on the above application/apply, apply to complete the installation
Enter "powerpc-linux-gnu-" in the command terminal and press "TAB" to complete the tool chain to view "powerpc-linux-gnu-gcc "
.