1. generate executable code on another platform through cross-compilation. Why is cross-compilation costly? One sentence: The last thing is. Sometimes it is because the target platform does not allow or cannot install the required compiler, and some features of the compiler are required. Sometimes it is because the resources on the target platform are poor, it is impossible to run the necessary compiler. Sometimes it is because the target platform has not yet been set up, and there is no operating system. It is impossible to run any compiler. & Nb
I. Cross-Compilation
Generate executable code on another platform. Why is cross-compilation costly? One sentence: The last thing is. Sometimes it is because the target platform does not allow or cannot install the required compiler, and some features of the compiler are required. Sometimes it is because the resources on the target platform are poor, it is impossible to run the necessary compiler. Sometimes it is because the target platform has not yet been set up, and there is no operating system. It is impossible to run any compiler.
To perform cross-compilation, We need to install the corresponding cross-compilation tool chain on the host platform, and then use this cross-compilation tool chain to compile the source code, finally, code that can be run on the target platform is generated.
Common examples of cross-compilation are as follows:
1. On Windows PC, the executable code for arm cpu can be compiled using ADS (ARM development environment) and armcc compiler.
2. Run the arm-Linux-gcc compiler on a linux PC to compile executable code for the Linux ARM platform.
3. Run the arm-elf-gcc compiler in the cygwin environment on a Windows PC to compile executable code for the arm cpu.
2. Glossary
In Linux, most software packages use Autoconf/Automake to automatically generate Makefile. /configure "," make ", and" make install "can install the program in Linux. When compiling third-party source code, you can check the readme and install files in the project. Generally, the compilation steps are written.
1../configure common parameters [-- build] | [-- host] | [-- target] | [-- prefix] | [-- help]
Note: host and -- host do not mean either. host is the host, that is, the platform for editing and compiling programs. -- host is the host for setting the execution file to run, it is a verb.
>./Configure: used to generate the corresponding Makefile;
> -- Build: the host that executes code compilation. Normally, it is your host system. If no host value is specified;
>>-- Host: the host of the compiled binary program, and the prefix of the Cross-compilation toolchain. This value is equivalent to build because the vast majority of tasks are executed on the local machine if they are compiled. However, different values must be set for build and host during cross-compilation. Use host to specify the running host, that is, host! = Cross-compilation is performed during build. If this parameter is not specified, 'config. guess 'is run to detect the vulnerability;
> -- Prefix: installation directory. For example, -- prefix =/usr indicates to install the software under/usr, the execution file will be installed in/usr/bin (instead of the default/usr/local/bin ), the resource file will be installed in/usr/share (instead of the default/usr/local/share );
> -- Help: view parameters;
>>-- Target: this parameter is special, indicating the name of the target platform to be processed. It mainly plays a role in programming language tools such as compiler and assembler context. If no host value is specified. It is generally used as a compilation tool. For example, to compile a gcc program that can process mips for the arm Development Board, -- target = mips;
>>>> Example: Compile gcc
>./Configure -- build = i386-linux -- host = arm-linux -- target = mipsel-linux -- prefix = $ (pwd)/_ install
Using the i386-linux compiler for gcc compilation, the compiled gcc runs in arm-linux, the compilation result is stored in the $ (pwd)/_ install path, the compiled gcc is used to compile the code that can be run in mipsel-linux.
2. Makefile contains some basic pre-defined operations:
> Make: Compile the source code based on Makefile, connect to generate the target file, and execute the file;
> Make clean: Clear the object files (Files suffixed with ". o") and executable files generated by the last make command;
> Make distclean: similar to make clean, but all files generated by configure are also deleted, including Makefile;
> Make test/make check: check make to ensure that there is no error in make. It is generally executed before make install;
> Make install: install the compiled executable files to the specified directory, which is generally the/usr/local/bin directory;
> Make dist: generate the publish package file (that is, the distribution package ). This command will pack executable files and related files into a tar.gz compressed file for software release. A file named "package-version.tar.gz" will be generated in the current directory. PACKAGE and VERSION are the AM_INIT_AUTOMAKE (PACKAGE, VERSION) defined in configure. in );
> Make distcheck: Generate and test the release package to confirm the correctness of the release package. This operation will automatically unbind the compressed package file, then execute the configure command, and execute make to confirm that there is no compilation error, and finally prompt that your software package is ready and can be released;
Iii. Cross-compiling source code
1. Environment
Ubuntu
2. Install Raspberry Pi cross compiling tool
Step1. download Raspberry Pi cross compiler tool https://github.com/raspberrypi/tools
Step 2: place the source code in a folder that users can share, such as/usr/tools.
Step Add the path of the Cross-compilation tool to the environment variable. I added it to bashrc for later startup.
1 $ nano ~ /. Bashrc
2 # Add: export PATH = $ PATH:/usr/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin at the end of the file
3 $ source. bashrc
Step 4. Check whether the installation is successful
Way1:
$ Arm # dual tab
Show the following content
Way2:
$ Arm-linux-gnueabihf-gcc-v
# Display correct information
$ Arm-linux-gnueabihf-g ++-v
# Display correct information
NOTE: If arm-linux-gnueabihf-XXX cannot be found during cross-compilation, check whether arm-linux-gnueabihf-XXX-v can output the correct information. If yes, you can switch to root for compilation.
3. Compile source code
1. When writing a compilation script, make sure that the compiler writes a cross-compiled compiler. For example, Makefile,
1 demo: $ (obj)
2 $ (CXX)-o $ ^ $ (LDFLAGS)
The CXX must be arm-linux-gnueabihf-g ++ to compile the correct executable files on Raspberry Pi.
2. Compile a third-party library
If you want to set global CC and CXX variables, enter the following command every time you open a new Terminal:
1 $ export CC = arm-linux-gnueabihf-gcc
2 $ export CXX = arm-linux-gnueabihf-g ++
Other global variables are the same as above.
Below are several common third-party library cross-compilation steps
1> sqlite3 http://www.sqlite.org/download.html sqlite-autoconf-3081002.tar.gz
Step 1: make clean
Step 2:./configure -- host = arm-linux-gnueabihf -- prefix =/usr/local/tools/sqlite3
Step 3: make
Step 4: make install
2> curl http://curl.haxx.se/download.html curl-7.43.0.tar.gz
Step 1: make clean
Step 2:./configure -- host = arm-linux-gnueabihf -- prefix =/usr/local/tools/curl
Step 3: make
Step 4: make install
3> openssl: http://www.openssl.org/source/ openssl-1.0.1p.tar.gz
Step 1:./config no-asm shared -- prefix =/usr/local/tools/openssl
Step 2: a. Modify Makefile CC = arm-linux-gnueabihf-gcc
B. Locate the location with-m64 and delete-m64.
Step 3: make
Step 4: make install
Install NodeJS http://www.linuxidc.com/Linux/2015-01/111714.htm on (Raspberry Pi) Raspberry Pi
Install Weston http://www.linuxidc.com/Linux/2013-06/86685.htm on Raspberry Pi
Linux OS for Raspberry Pi already available http://www.linuxidc.com/Linux/2012-03/56058.htm
Raspberry Pi (Raspberry Pi) trial note Co., http://www.linuxidc.com/Linux/2013-10/91008.htm.
Raspberry Pi (Raspberry Pi) installation, configuration of IP and software sources and other entry-level http://www.linuxidc.com/Linux/2013-10/91009.htm
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-08/121319.htm