mac搭建嵌入式编程环境--交叉编译工具链crosstool-ng

1.  第一个思路就是和ubuntu一样,是否有apt-get一样的管理软件包工具。查了一下有类似的macport和homebrew

  macport下载方法:https://guide.macports.org/#installing.xcode,直接下载dmg镜像安装即可

  brew下载方法方法:https://brew.sh/按照官网下载安装

   下面是换源方法:

-------------------------------------------------------------------------------------------------

  (1)macport  查看/opt/local/etc/macports/macports.conf发现https://trac.macports.org/wiki/Mirrors#MacPortsSource

  最下面有中国过的服务器,搜了一下发现是上海大学的,按照指示添加rsync_server和rsync_dir,另外的修改/opt/local/etc/macports/sources.conf在最下面添加rsync://mirrors.shu.edu.cn/macports/release/ports/ [default]

  (2)brew  https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/上面有很详细的方法,不赘述。

-------------------------------------------------------------------------------------------------

  首先我们要下载交叉编译工具链:arm-none-linux-gnueabi-gcc 

  brew没有交叉工具链的包,macport也是只有一个很旧的包。

  没有就没有吧,那我去下载一个,http://www.veryarm.com/arm-none-linux-gnueabi-gcc  也没有mac的版本。

  下不到就下不到吧,那我自己编译一个。http://crosstool-ng.github.io/ 

  注:关于mac文件系统不区分大小写:就在磁盘工具里面添加卷,选择有大小写的,存储大小搞大一点10个G,上次5G不够用。

大小写盘

  命令行进入你的大小写分区。

  ct-ng命令行里面打出来后回车就有帮助选项。ct-ng list-samples 把所有例子列出来了,有arm-unknown-linux-gnueabi就是我们4412想要的。

  直接ct-ng arm-unkown-linux-guneabi 会把conf文件导入到现在的你所在的位置。

  Paths and misc options--Local tarballs directory这个是你下载依赖包的文件夹,修改你大小写分区的位置。Prefix directory 也是把 home 替换成大小写分区位置。

path

  下面是https://stackoverflow.com/questions/5245444/cross-compiler-for-linux-on-mac-os-x 摘录

 

    1. install the xcode base build tools
    2. install the optional xcode command line tools
    3. install homebrew
    4. install the homebrew build tools
      4.1 brew install crosstool-ng mpfr gmp grep
      4.2 brew tap homebrew/dupes
    5. create a case sensitive volume using "disk utility"
    6. use this volume to build the tool chain itself
      6.1 generate a base configuration (for me this is an arm cortex a8)
      6.1.1 ct-ng arm-cortex_a8-linux-gnueabi
      6.2 use menuconfig (ct-ng menuconfig) to tweak the configuration
      6.2.1. disable fortran and java (c compiler)
      6.2.2. turn off static linking (c compiler)
      6.2.3. change the paths to be on the volume you created above (paths and misc options)
      6.2.4. remove dmalloc (debug facilities)
      6.3 invoke the build:
      6.3.1 ulimit -n 1024 //这里是在我的mbp里面是不够的  sudo ulimit -n 2048才解决
      6.3.2 ct-ng build

 

  上面已经写的很清楚了,修改了几处添加了armv7-a的架构,就开始build了,报错。在复制getext库的时候出错了

  ---20180909更新

  因为我没有太多的查看build.log,现在出查看了他,发现缺少了automake1.5.0的工具,在menuconfig里面设置automake [X]

  ulimit -n 2048  还有就是创建的大小写的盘

  最后我编译成功了 哈哈哈哈哈

 

2.  为了不使用虚拟机,试试docker,好吧虽然都是虚拟的。mac 安装 docker 官网就有然后就是拉镜像docker pull synapsedev/gcc-arm-none-eabi

  我已经把镜像拉下来了,运行docker run -it -v ~/build-tool:/home synapsedev/gcc-arm-none-eabi

  -it 选项是一起配合的大概就是进入里面运行交互的命令行,-v就是和本地的文件和里面的文件关联,也就是挂载。

  在镜像里面,我们在/home下用vim写了一个测试浮点的程序helloworld。使用/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/arm-none-eabi-gcc 编译,发现报错

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':

exit.c:(.text.exit+0x2c): undefined reference to `_exit'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':

sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':

writer.c:(.text._write_r+0x24): undefined reference to `_write'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':

closer.c:(.text._close_r+0x18): undefined reference to `_close'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':

fstatr.c:(.text._fstat_r+0x20): undefined reference to `_fstat'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':

isattyr.c:(.text._isatty_r+0x18): undefined reference to `_isatty'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':

lseekr.c:(.text._lseek_r+0x24): undefined reference to `_lseek'

/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':

readr.c:(.text._read_r+0x24): undefined reference to `_read'

  到https://stackoverflow.com/questions/19419782/exit-c-text0x18-undefined-reference-to-exit-when-using-arm-none-eabi-gcc  在交叉编译的时候,更加要关注工具链的选项,提及了semihosting,大概就是现在的运行环境并不是在目标机上面,处于non-semihosting/retarget状态,要加上 --specs=nosys.specs 

  也就是/usr/local/bin/gcc-arm-none-eabi-6_2-2016q4/bin/arm-none-eabi-gcc --specs=nosys.specs  -o test test.c 

 

 

posted @ 2018-09-05 08:46  AAAron  阅读(1598)  评论(0编辑  收藏  举报