简书链接:mac交叉编译
文章字数:349,阅读全文大约需要1分钟
https://github.com/crosstool-ng/crosstool-ng/releases
下载最新版

该分支对编译中出现的一些编译error,进行了修正,并对mulitlib的编译进行了一定程度的修正

编译和安装

1
cd crosstool-ng
1
2
 xattr -d com.apple.quarantine ./configure //bad interpreter: Operation not permitted
chmod 777 ./configure

指定安装路径(默认安装在/usr/local下).,和mac下的一些ports工具,如gobjcopy,这些可以通过mac-ports 安装

1
2
./bootstrap 
./configure --prefix=${install_path} --with-objcopy=/opt/local/bin/gobjcopy --with-objdump=/opt/local/bin/gobjdump --with-libtool=/opt/local/bin/glibtool --with-readelf=/opt/local/bin/greadelf --with-gbtoolize=/opt/local/bin/glibtoolize
1
2
make
make install

使用crosstool-ng编译arm工具链

ct-ng menuconfig
由于mac有些限制,有些地方需要特别设定下
具体步骤如下:
make version 3.82在编译glibc时有问题,打开EXPERIMENTAL feature以便使用自带的make
Paths and misc options —> [*] Try features marked as EXPERIMENTAL

打开debug功能,以便可以进行单个step的编译,而不是每次都重新编译所有的

1
2
3
4
Paths and misc options  ---> [*] Debug crosstool-NG 
---> Debug crosstool-NG
---> gzip saved states (NEW)
Paths and misc options ---> Maximum log level to see: (INFO)

根据自己的需要定制cpu

1
2
3
4
5
6
7
8
9
10
11
12
Target options  --->   Target Architecture (arm)
Target options ---> (armv6k) Architecture level
Target options ---> (arm1176jzf-s) Tune for CPU
Target options ---> (vfp) Use specific FPU

Operating System ---> Target OS (linux)
Operating System ---> Linux kernel version (2.6.32.60 (longterm))

C compiler ---> C compiler (gcc)
C compiler ---> [*] Show Linaro versions
C compiler ---> gcc version (linaro-4.6-2013.04)
C compiler ---> [*] C++

apple gcc不支持静态链接,关闭静态链接

1
C compiler  ---> [ ] Link libstdc++ statically into the gcc binary

这里使用glibc 2.13

1
2
C-library  --->  C library (glib) 
C-library ---> glibc version (2.13)

使用4.3.2的GMP,5.0+的存在编译问题

1
Companion libraries  ---> GMP version (4.3.2)

编译自定义的make,

1
2
Companion tools  --->  [*] Build some companion tools 
Companion tools ---> [*] make

Esc Esc 保存并退出设定界面

编译工具链

1
ct-ng build

编译完成后,工具链默认存放在在~/x-tools/下
image.png