交叉编译指令

Makefile 规则格式

Makefile 里面是由一系列的规则组成的,这些规则格式如下:

目标…... : 依赖文件集合……
命令 1
命令 2
……
或
目标…... : 依赖文件集合……;命令 1
命令 2
……

1、gcc交叉编译指令的一些选项含义:

样例:
arm-linux-gnueabihf-gcc -Wall -nostdlib -c -O2 $(INCLUDE) -o $@ $<
1)总体选项:
-c:预处理,编译和汇编源文件,但不做连接,编译器根据源文件生成OBJ文件
-S:编译后停止
-E:预处理后停止
-o file :指定输出文件 file
-v:显示编译细节
-Wa,-mimplicit-it=thumb 将逗号分隔的-mimplicit-it=thumb传递给汇编器

2)警告选项:
-w:的意思是关闭编译时的警告,也就是编译后不显示任何warning,因为有时在编译之后编译器会显示一些例如数据转换之类的警告,这些警告是我们平时可以忽略的
-W:选项类似-Wall,会显示警告,但是只显示编译器认为会出现错误的警告。
-Wall:选项意思是编译后显示所有警告。

3)连接器选项:
-I library :连接名为 library 的库文件
-nostartfiles : 不连接系统标准启动文件,二标准库文件仍然正常使用
-nostdlib : 不连接系统标准启动文件和标准库文件,只把指定的文件传递给连接器
-static : 在支持动态连接的系统上阻止连接共享库
-shared : 生成一个共享OBJ文件,它可以和其他OBJ文件连接产生可执行文件
-Xlinker option : 把选项option传递给连接器
-Wl ,option : 把选项option传递给连接器
-u symbol : 使连接器认为取消了 symbol 的符号定义,从而连接库文件以取得定义

4)优化选项:
-O、-O1
-O2
-O3
-O0

5)调试选项:
-g:产生调试信息
$(INCLUDE):
指明头文件(包含路径)

2 、arm-linux-ld是一个链接程序工具,

1)其作用主要是将汇编过的多个二进制文件进行链接,成为一个可执行的二进制文件,这个命令的选项有好多,具体用到的时候大家可以使用–help 选项来查看具体的选项用法。
选项用法选项用法:

2)下面将几个重要的命令介绍一下:
-T File --script FILE指定一个链接器脚本文件,指示编译器按照脚本进行链接;
-Tbss ADDRESS bss段的链接地址;
-Ttext ADDRESS 代码段链接地址;
-Tdata ADDRESS 数据段链接地址;
-r --relocateable 产生可重定向的输出,比如,产生一个输出文件它可再次作为‘ld’的输入,这经常被叫做“部分链接”,当我们需要将几个小的.o文件链接成为一个.o文件的时候,需要使用此选项。
-e 指定程序的入口标号;
-l LibName 指定要链接的库;
-L Directory 增加库文件的搜索路径;
-o FILE 设置输出文件名;
-O 输出文件最优;
-a 指定arch体系;

3)例如:
arm-linux-ld -Ttext 0x10000000 main.o -o main_elf
这句话是将main.o 文件连接成ELF格式文件,在连接的过程中,-Ttext 0x10000000这个选项告诉连接器我的这段main.o程序需要被加载到RAM的0x10000000地址处执行。所以在连接的时候main.o第一条语句的连接地址就是0x10000000,第二条语句就是跟在其后面。有很多人都议论连接地址和运行地址这个怎么说的都有。运行地址可以等于连接地址,还可以认为运行地址是pc指针指向的地址,就是正在执行指令的地址。只要理解了这个概念就可以了。

3、 arm-linux-gnueabihf-objcopy 格式转换

4、 arm-linux-gnueabihf-objdump 反汇编

5、都有哪些交叉编译器

1)本地编译器
编译器可以生成用来在与编译器本身所在的计算机和操作系统(平台)相同的环境下运行的目标代码,这种编译器又叫做“本地”编译器。
2)交叉编译器
编译器也可以生成用来在其它平台上运行的目标代码,这种编译器又叫做交叉编译器。交叉编译器在生成新的硬件平台时非常有用。
3)工作方法
首先编译器进行语法分析,也就是要把那些字符串分离出来。
然后进行语义分析,就是把各个由语法分析分析出的语法单元的意义搞清楚。
最后生成的是目标文件,也称为obj文件。
再经过链接器的链接就可以生成最后的可执行代码了。
有些时候需要把多个文件产生的目标文件进行链接,产生最后的代码。这一过程称为交叉链接。
4)举例交叉编译
1、在Windows PC上,利用ADS(ARM开发环境),使用armcc编译器,则可编译出针对ARM CPU的可执行代码。
2、在Linux PC上,利用arm-linux-gcc编译器,可编译出针对Linux ARM平台的可执行代码。
3、在Windows PC上,利用cygwin环境,运行arm-elf-gcc编译器,可编译出针对ARM CPU的可执行代码。
4、在Windows系统上,利用Keil Uvison工具,开发出运行在89C51单片机上的程序。
5、在Windows系统上,利用CodeWarrior IDE工具,开发出运行在Freescale XS128单片机上的程序。

6、arm-linux-gnueabihf-gcc --help

gnueabi和gnueabihf的区别

lj@lj-virtual-machine:~$ arm-linux-gnueabihf-gcc -v
使用内置规格。
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/lto-wrapper
目标: arm-linux-gnueabihf
配置为: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-armhf-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-armhf-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-armhf-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include
线程模型: posix
gcc 版本 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 

lj@lj-virtual-machine:~$ arm-linux-gnueabihf-gcc --help
用法: arm-linux-gnueabihf-gcc [选项] file...
选项:
  -pass-exit-codes         以阶段中的最高错误代码退出
  --help                   显示此信息
  --target-help            显示特定于目标的命令行选项
  --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
                           显示特定类型的命令行选项
  (使用“-v--help”显示子进程的命令行选项)
  --version                显示编译器版本信息
  -dumpspecs               显示所有内置等级库字符串
  -dumpversion             显示编译器的版本
  -dumpmachine             显示编译器的目标处理器
  -print-search-dirs       显示编译器搜索路径中的目录
  -print-libgcc-file-name  显示编译器配套库的名称
  -print-file-name=<lib>   显示库<lib>的完整路径
  -print-prog-name=<prog>  显示编译器组件<prog>的完整路径
  -print-multiarch         显示目标的标准化GNU三元组,用作库路径中的组件
  -print-multi-directory   显示libgcc版本的根目录
  -print-multi-lib         显示命令行选项和多个库搜索目录之间的映射
  -print-multi-os-directory 显示操作系统库的相对路径
  -print-sysroot           显示目标库目录
  -print-sysroot-headers-suffix 显示用于查找标头的sysroot后缀
  -Wa,<options>            将逗号分隔的<options>传递给汇编程序
  -Wp,<options>            将逗号分隔的<options>传递给预处理器
  -Wl,<options>            将逗号分隔的<options>传递给链接器
  -Xassembler <arg><arg>传递给汇编程序
  -Xpreprocessor <arg><arg>传递给预处理器
  -Xlinker <arg><arg>传递给链接器
  -save-temps              不删除中间文件
  -save-temps=<arg>        不删除中间文件
  -no-canonical-prefixes   构建其他gcc组件的相对前缀时,不要规范化路径
  -pipe                    使用管道而不是中间文件
  -time                    每个子流程的执行时间
  -specs=<file>            使用<file>的内容覆盖内置规格
  -std=<standard>          假设输入源用于<标准>
  --sysroot=<directory>    使用<directory>作为标头和库的根目录
  -B <directory><directory>添加到编译器的搜索路径
  -v                       显示编译器调用的程序
  -###                     类似于-v,但引用的选项和未执行的命令
  -E                       仅预处理;不编译、汇编或链接
  -S                       仅编译;不要组装或连接
  -c                       编译和汇编,但不链接
  -o <file>                将输出放入<file>
  -pie                     创建位置无关的可执行文件
  -shared                  创建共享库
  -x <language>            指定以下输入文件的语言允许的语言包括:c c++汇编程序none“none”表示恢复到基于文件扩展名猜测语言的默认行为
  
以-g、-f、-m、-O、-W或--param开头的选项会自动传递给arm-linux-gnueabihf-gcc调用的各个子进程。为了将其他选项传递给这些进程,必须使用-W<letter>选项。

有关错误报告说明,请参见:
<file:///usr/share/doc/gcc-5/README.Bugs>.

7、下载

可以使用 Linaro 出品的交叉编译器, Linaro 是一间非营利性质的开放源代码软件工程公司, Linaro 开发了很多软件,最著名的就是 Linaro GCC 编译工具链(编译器),关于 Linaro 详细的介绍可以到 Linaro 官网查阅

在这里插入图片描述

8、config.log

此文件包含编译器生成的任何消息。运行configure,以在configure出错时帮助调试。

9、ubuntu 16.04 LTS的gcc命令

ubuntu 16.04 LTS的gcc命令与arm-linux-gnueabihf-gcc差不多

eaidk@ubuntu:~$ gcc -v
使用内置规格。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
目标: x86_64-linux-gnu
配置为: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
线程模型: posix
gcc 版本 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 

eaidk@ubuntu:~$ gcc --help
用法: gcc [选项] file...
选项:
  -pass-exit-codes         Exit with highest error code from a phase
  --help                   Display this information
  --target-help            Display target specific command line options
  --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
                           Display specific types of command line options
  (Use '-v --help' to display command line options of sub-processes)
  --version                Display compiler version information
  -dumpspecs               Display all of the built in spec strings
  -dumpversion             Display the version of the compiler
  -dumpmachine             Display the compiler's target processor
  -print-search-dirs       Display the directories in the compiler's search path
  -print-libgcc-file-name  Display the name of the compiler's companion library
  -print-file-name=<lib>   Display the full path to library <lib>
  -print-prog-name=<prog>  Display the full path to compiler component <prog>
  -print-multiarch         Display the target's normalized GNU triplet, used as
                           a component in the library path
  -print-multi-directory   Display the root directory for versions of libgcc
  -print-multi-lib         Display the mapping between command line options and
                           multiple library search directories
  -print-multi-os-directory Display the relative path to OS libraries
  -print-sysroot           Display the target libraries directory
  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers
  -Wa,<options>            Pass comma-separated <options> on to the assembler
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor
  -Wl,<options>            Pass comma-separated <options> on to the linker
  -Xassembler <arg>        Pass <arg> on to the assembler
  -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
  -Xlinker <arg>           Pass <arg> on to the linker
  -save-temps              Do not delete intermediate files
  -save-temps=<arg>        Do not delete intermediate files
  -no-canonical-prefixes   Do not canonicalize paths when building relative
                           prefixes to other gcc components
  -pipe                    Use pipes rather than intermediate files
  -time                    Time the execution of each subprocess
  -specs=<file>            Override built-in specs with the contents of <file>
  -std=<standard>          Assume that the input sources are for <standard>
  --sysroot=<directory>    Use <directory> as the root directory for headers
                           and libraries
  -B <directory>           Add <directory> to the compiler's search paths
  -v                       Display the programs invoked by the compiler
  -###                     Like -v but options quoted and commands not executed
  -E                       Preprocess only; do not compile, assemble or link
  -S                       Compile only; do not assemble or link
  -c                       Compile and assemble, but do not link
  -o <file>                Place the output into <file>
  -pie                     Create a position independent executable
  -shared                  Create a shared library
  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension

Options starting with -g, -f, -m, -O, -W, or --param are automatically
 passed on to the various sub-processes invoked by gcc.  In order to pass
 other options on to these processes the -W<letter> options must be used.

For bug reporting instructions, please see:
<file:///usr/share/doc/gcc-5/README.Bugs>.
eaidk@ubuntu:~$ 

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值