First, cross-compiling
Generate executable code on another platform on one platform. Why do you have to cross-compile it? In a word: It is the last resort. Sometimes it is because the target platform is not allowed or unable to install the required compiler, but also need some characteristics of the compiler, sometimes because the target platform is resource-poor, unable to run the required compiler, and sometimes because the target platform has not been established, and even the operating system is not, not to run what compiler.
To cross-compile, we need to install the corresponding cross-compilation toolchain on the host platform (compilation tool chain), then compile the source code with this cross-compilation toolchain and eventually build the code that will run on the target platform.
Common cross-compilation examples are as follows:1. On a Windows PC, with the ADS (ARM development environment), using the ARMCC compiler, you can compile executable code for ARM CPUs. 2. On a Linux PC, using the ARM-LINUX-GCC compiler, you can compile executable code for the Linux arm platform. 3. On a Windows PC, using the Cygwin environment, run the ARM-ELF-GCC compiler to compile executable code for the ARM CPU. second, the noun explanationwhen compiling third-party source code, you can look at the Readme and install files in the project, and generally write the compilation steps. 1./configure Common parameters [--build] | [--host] | [--target] | [--prefix] | [--help]
Note: Host and--host is not a mean, host is the host, that is, the platform to edit and compile the program, is a noun;--host is a verb to set the host on which the execution file runs. >>./configure: Used to generate the corresponding Makefile;>>--build: Perform code compilation of the host, Normal is your host system. If no value is specified using host;
>>--host: The compiled binaries are executed by the host, which prefixes the cross-compilation toolchain. This value is equal to build, because the vast majority of this is done natively if the machine is compiled. However, when cross-compiling, the build and host need to set different values, using host to specify the running host, that is, the host! = Build when the compilation is cross-compilation. If no designation will run ' config.guess ' to detect;>>--prefix: installation directory; >>--help: view parameters;>>--target: This parameter is special, indicating the target platform name that needs to be processed, primarily in the context of program language tools such as compilers and assembler, if no value is specified using host. Generally used to compile tools, such as to the arm Development Board to compile a can handle the MIPS program of GCC, then--target=mips;2. Example: Compiling gcc>>/configure--build=i386-linux--host=arm-linux--target=mipsel-linux--prefix=$ (pwd)/_install Compile the GCC with I386-linux compiler, compile the GCC run in Arm-linux, the compilation result is stored in the $ (PWD)/_install path, the compiled GCC used to compile can be in the Mipsel- Code that runs under Linux. third, cross-compiling source code1. EnvironmentUbuntu 2. Raspberry Pi Cross-compilation tool installation
Step1. Download Raspberry Pi Cross Compilation Tool Https://github.com/raspberrypi/tools
Step2. Place the source in a folder that can be share by each user, such as/usr/tools
Step3. Add the path of the cross-compilation tool to the environment variable, I added it to the BASHRC in order to start it later without setting it up.
1 $nano ~/. BASHRC2# at the end of the file add: Export path= $PATH:/usr/tools/arm-bcm2708/ Gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin3$source . BASHRC
Step4. Detect if the installation was successful
Way1:
$arm # Double tab
Show the following:
Way2:
$arm-LINUX-GNUEABIHF-GCC-# can display the correct information $arm-linux-gnueabihf-g++- # to display the correct information
Note: cross-compilation, if the occurrence of arm-linux-gnueabihf-xxx cannot be found, determine whether arm-linux-gnueabihf-xxx-v can output the correct information, if possible, can be cut to the root of the compilation
Third, compile the source code
1. When writing a compile script, make sure that the compiler writes a cross-compiled compiler. such as the more commonly used makefile,
1 Demo: $(obj)2 $ (CXX)-o [email protected] $^ $ (ldflags)
The cxx must be arm-linux-gnueabihf-g++ to compile the correct executable file on the Raspberry Pi.
2. Compiling third-party libraries
If you want to set the global cc and CXX variables, enter the following command each time you open a new Terminal :
1 $export cc=arm-linux-gnueabihf-gcc 2$export
The other global variables are the same as above.
Cross-compiling steps with the following common third-party libraries
1>> sqlite3 http://www.sqlite.org/download.html sqlite-autoconf-3081002.tar.gz
Step1: make clean
Step2:./configure--HOST=ARM-LINUX-GNUEABIHF--prefix=... / Xxx
Step3: make
Step4: Make install
2>>Curl http://curl.haxx.se/download.html curl-7.43.0.tar.gz
SteP1: make clean
Step2:./configure--host=arm-linux-gnueabihf--prefix=..... / Curl
Step3: make
Step4: Make install
3>> OpenSSL: http://www.openssl.org/source/ openssl-1.0.1p.tar.gz
Step1:./config no-asm Shared--prefix=....../openssl
Step2:a, modify Makefile CC=ARM-LINUX-GNUEABIHF-GCC
B, find the place with-m64, will-m64 delete.
Step3:make
Step4:make Install
Ubuntu Implements Raspberry Pi cross compilation