arm-linux-gcc
- Structure and level of knowledge - program compilation and debugging
- Embedded cross compiler installation configuration
- Host target board development model
- Under ARM microprocessor / Linux system compiler
- Download and install the compiler
- arm-linux-gcc tool
- `-E`
- `-S`
- `-c `
- `-o`
- `-include file`
- `And dir`
- `-I`
- `-iprefix prefix` 和 `-iwithprefix dir`
- `` -L library name
- `` -L directory
- gcc optimization
- after class homework
Linux development tools designed to make and makefile
Structure and level of knowledge - program compilation and debugging
Embedded cross compiler installation configuration
Host target board development model
-
Host
compile, link embedded computer software -
Target machine
running embedded software, hardware platform -
"Local" compiler
to generate object code that runs under the compiler itself where the same computer and operating system environment (platforms), Windows such as Windows environment to generate the object code. -
Cross compiler
Used to generate the object code to run on other platforms, such as Windows Linux environment generates object code.
Under ARM microprocessor / Linux system compiler
The compiler naming rules
arch [-vendor] [-os] [-(gnu)eabi]-工具名称
arch
- architectures, such as ARM , MIPSvendor
- tool chain providers, the CPU name or a development board manufacturersos
- target operating systems, such as linux(gnu) eabi
- the use of libraries, including glibc , EABI , uclibc three kinds
Example: arm-none-eabi-gcc
- Bare-metal system used to compile the ARM architecture
Example:arm-none-linux-gnueabi-gcc
- For Linux systems based on ARM architecture, based on GCC, Glibc library use
after Codesourcery company introduced optimized compiler for compiling the ARM architecture u-boot, Linux kernel, linux applications.
Several important directories:
compiler tool directory:FriendlyARM/toolchain/4.9.3/bin
The compiler header file directory:FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root/usr/include
Library file directory:FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root/usr/lib
Download and install the compiler
You can go to the official website to download, http://www.linaro.org/downloads/
but more slowly, can be directly downloaded with me.
Links: https://pan.baidu.com/s/1jL_G6kbTC9h_bF8HHXBWxw extraction code: 67u4
1. First move the package to install the downloaded tmp directory under the root directory (/ tmp)
2. Use tar command to extract the installation package, the following command is entered in the Terminal :( preceding sudo indication root authority to execute the command)
sudo tar -xjvf /tmp/arm-linux-gcc-4.6.4-arm-x86_64.tar.bz2 -C /
Note that uppercase letters C, this command will opt to install the package and extract the root directory TuxamitoSoftToolchains inside (/ opt / TuxamitoSoftToolchains)
3. After the extraction is completed, and then create a new directory in the arm (/ usr / local), namely, enter the following command in the Terminal:
sudo mkdir /usr/local/arm
After you create a successful directory arm, also need to give it to liberate all the privileges that enter the following command in the Terminal:
sudo chmod 777 /usr/local/arm
4. Locate the extract from the directory and copy the entire gcc-4.6.4 directory to the newly-built arm directory, the command is as follows:
first cd to gcc 4.6.4-directory (after switching the first look there ls no gcc-4.6.4 directory):
cd /opt/TuxamitoSoftToolchains/arm-arm1176jzfssf-linux-gnueabi/
And then execute the copy command cp, -r represent anything inside as well as the entire directory
sudo cp -r gcc-4.6.4 /usr/local/arm
5. Open (/ etc / profile) configuration database environment variables and variables, the object is to be used later at any position of the cross compiler command is as follows:
sudo vi /etc/profile
After vi or vim open, adding two lines at the end of the file, and enter the following code: The first line is to add the program execution environment variables, the second line is the path of the library file
export PATH=$PATH:/usr/local/arm/gcc-4.6.4/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/arm/gcc-4.6.4/lib
Then save out.
6. Use the source command to reload the configuration file to take effect
source /etc/profile
7. Verify that the installation was successful, output version information Enter the following command in Terminal:
arm-linux-gcc -v
arm-linux-gcc tool
arm-gcc-linux syntax: arm-linux-gcc [ option | filename ]...
Under normal circumstances, produce a new program needs to go through four stages: preprocessing, compiler, assembler, linker
, of course we can decide what steps to compile the operations performed by the end of the parameter
parameter range in Linux seek the help of the environment:man arm-linux -gcc
-E
- Only the file preprocessing , but do not compile, assemble and link.
Example:
arm-linux -gcc -E hello.c -o hello1.c
Pretreatment, Hello.c contents:
After pretreatment, Hello1.c contents:
-S
- Only the file compiled (generated assembler file .s) , but does not compile and link.
Example: arm-linux -gcc -S hello.c
the above example will generate a compiled file hello.s
-c
- Only the file compiled and assembled, but it is not linked, meaning that only the program make obj file.
Example: arm-linux -gcc -c hello.c –o hello.o
-o
- Specify the target name, the default time, gcc compiler is a.out file
Example:
arm-linux -gcc hello.c
The default compile hello.out
arm-linux -gcc -o hello.bin hello.c
target noun is hello.bin
arm-linux -gcc -o hello.s -S hello.c
-include file
- It contains a code that, in simple terms, is to compile a file when you need another file, you can use it to set function is equivalent to use in your code
#include
.
Example:arm-linux -gcc hello.c -include type.h
-I dir
- If you use
#include"file"
time, gcc / g ++ will first look in the current directory you specified in the header files, if not found, the compiler will default to the header file directory to find; - If you use a
-I
specified directory, the compiler will first look for the directory you specify, and then press the conventional sequential go.
Example: arm-linux -gcc -o hello -I/xxx/include hello.c
-I
- Before canceling function is a parameter, it is generally in
-I dir
after use
-iprefix prefix
with -iwithprefix dir
These two parameters are generally used in conjunction, when -I
a directory lookup fails, to prefix+dir
find the next
-l库名
- Specifies the compile time libraries used ( static library .a / DLL .so )
Example: arm-linux-gcc -lpthread hello.c
Specifies the use of phtread.c
the library
-L目录
- Compile time specified, the library search path. For example, your library, you can
-L
specify the directory where your library, otherwise the compiler will only find in the standard library directory . Thisdir
is the name of the directory.
Example:
arm-linux-gcc –L./ hello.c –o hello
gcc optimization
Providing gcc in order to meet different levels of optimization of user needs and provide nearly a hundred kinds optimization options, used to { compile time , the target file size , the efficiency } This three-dimensional model of a different trade-offs and balancing. Optimization methods and so forth, as a whole will have the following categories:
- Reduce operation instruction;
- Try to meet the cpu pipelining;
- By guess the behavior of the program, re-adjustment execution code sequence;
- Full use of registers;
- Calls for simple expansion, etc.
-O0
, -O1
, -O2
, -O3
O0: do not do any optimization, which is the default compiler options
O3: highest level of optimization
-g
- The compiler generates debugging information at compile time.
Example:
arm-linux –gcc –o hello -g hello.c
after class homework
(1) belonging to the watchdog member ( hardware module ), which is a core function ( detection software code runaway ) and ( when the system is "running out" into the loop and restore the operation of the system ).
(2) assuming C code fun.c, which is compiled into object code fun.o, compile command arm-linux-gcc -c fun.c -o fun.o
; if using a library function fun.c libcurses.a, and which together with the compiled executable main.c smartfun , the compiler command arm-linux-gcc -c fun.c main.c -lcurses -o smartfun
.