arm-none-eabi-gcc源码编译toolchain构建过程

arm-none-eabi-gcc源码编译toolchain构建过程
背景
我们采⽤arm公司的芯⽚,arm会提供官⽅⽀持的编译 toolchain,访问地址:
源码编译的好处,可以客制化⼀些features,features都是通过宏开关控制,⽐如arm 的gcc中 针对freertos 砍去了posix,所以需要⼿动打开posix 开关
gcc-arm-none-eabi 源码编译
下载解压源码
把gcc-arm-none-eabi-6-2019-q3-update-linux.tar.bz2解压出来
How-to-build-toolchain.pdf
ARM 公司已经给了编译的参考⽂档,最主要的就是搭建可以跑起来的编译gcc的环境
以下,在⽂档中都有介绍,按照步骤操作
1. ubuntu的编译环境
最好是ubuntu14.04 以上的版本,也可以是win10 linux ⼦系统18.04(本⼈实践环境)
2. 环境搭建
$ sudo su
$ apt-get install software-properties-common
$ add-apt-repository universe
编辑⽂本 /etc/apt/sources.list.d/xenial.list
deb archive.ubuntu/ubuntu xenial main universe
deb-src archive.ubuntu/ubuntu xenial main universe
deb security.ubuntu/ubuntu xenial-security main
⽤来⽀持⽀持32bit的包
dpkg --add-architecture i386
更新所有的包
apt-get update
安装⽣成windows 环境的包
apt-get install -y -t xenial \
gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686
安装所有的⼯具包
apt-get -f install -y \
build-essential \
澳门特别行政区区徽autoconf \
autogen \
bison \
dejagnu \
flex \
flip \
gawk \
git \
gperf \
gzip \
nsis \
openssh-client \泄压阀
p7zip-full \
perl \
python-dev \
libisl-dev \
scons \
tcl \
texinfo \
tofrodos \
wget \
zip \
texlive \
texlive-extra-utils \
libncurses5-dev
# 退出sudo 权限
exit
进⼊解压⽬录下
3. 编译步骤
正常OK的步骤如下
./install-sources.sh
./build-prerequisites.sh
./build-toolchain.sh
注意事项
1. 整个编译过程⼗分耗时,所以建议每⼀步都⼗分仔细,整个过程最长6.5⼩时
2. 官⽅⽂档建议体跳过mingw32 的环境包,加快速度,建议跳过
3. 在win10 的linux ⼦系统下,必须将源码放置在 ~ 主⽬录下⾯⾃⼰创建⼀个toolchain⽬录下,放在e盘或者d盘其他盘,会导致不
到头⽂件(猜测,微软linux⼦系统和windows 本⾝的⽂件系统兼容性做的不好)
4. 编译的时候按照我的步骤加快编译和避开编译其他错误
# 下载和解压依赖
./install-sources.sh --skip_steps=mingw32
# 下载包的时候,可能会出现缺少包
# 检查 build-common.sh⽂件所有安装包的链接和对应版本,缺少的话⼿动下载放在src⽬录下# build-common.sh 中需要下载的依赖包的链接
/download/gmp/gmp-6.1.0.tar.bz2
/mpfr-3.1.4/mpfr-3.1.4.tar.bz2
ftp:///gnu/mpc/mpc-1.0.3
isl.gforge.inria.fr/isl-0.18
downloads.sourceforge/project/expat/expat/expat-2.1.1/expat-2.1.1.tar.bz2 /linux/misc/old/libelf-0.8.
/pub/gnu/libiconv/libiconv-1.
www.zlib/fossils/zlib-1.2.
nsis.sourceforge/mediawiki/images/a/ad/EnvVarUpdate.7z
/ftp/python/python-2.7.13.msi
# 再次执⾏
./install-sources.sh --skip_steps=mingw32
./build-prerequisites.sh --skip_steps=mingw32
# ⽣成 linux版本免安装 toolchain
执⾏命令
./build-toolchain.sh \
--skip_steps=mingw32,manual,gdb-with-python,mi
ngw32-gdb-with-python
–skip_steps 就是 所有源码安装依赖包 configure 步骤中配置的参数
mingw32 是跳过 ⽣成32位系统 免安装toolchain
manual 不⽣成 pdf 和html等说明⽂档
-gdb- 相关参数跳过所有的gdb调试⼯具⽣成
整个过程3⼩时15分钟
基本上⼀个源码编译⽣成的免安装gcc toolchain 可以进⾏玩耍了
记得盯着编译过程,就知道为什么编译时间这么长了
www.kepuwin10 linux ⼦系统会打包失败,如:
增加posix gcc编译
因为想拥有⽀持多线程posix的 gcc,那么上⾯的gcc ⼯具features中并没有⽀持posix,编译报错是合理的
查看编译器⽀持features
那么需要在⽀持posix 配置的依赖库的源码中,在./configure 增加参数–enable-threads=posix (默认是 --enable-threads=single 即 --disable-threads)
所以 中将所有 的–disable-threads 替换为 --enable-threads=posix ,让编译器⽀持 posix threads,修改后再次编译
但是编译后,出现编译报错
编译出错,说明我们的编译器不⽀持posix,所以需要看具体错误
的错误,指出 在mutls.c 中引⽤了gthr.h 包含头⽂件中的gthr-default.h 中的pthread 但是不识别
到源码:在gcc 源码包中到gthr.h 注释说明了如何⼿动修改⽀持 posix
/* If this file is compiled with threads support, it must
#define __GTHREADS 1
to indicate that threads support is present.  Also it has define
function
int __gthread_active_p ()
that returns 1 if thread system is active, 0 if not.
The threads interface must define the following types:
__gthread_key_t
__gthread_once_t
__gthread_mutex_t
__gthread_recursive_mutex_t
The threads interface must define the following macros:
__GTHREAD_ONCE_INIT
to initialize __gthread_once_t
__GTHREAD_MUTEX_INIT
to initialize __gthread_mutex_t to get a fast
non-recursive mutex.
__GTHREAD_MUTEX_INIT_FUNCTION
to initialize __gthread_mutex_t to get a fast
non-recursive mutex.
Define this to a function which looks like this:
void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
Some systems can't initialize a mutex without a
function call.  Don't define __GTHREAD_MUTEX_INIT in this case.
__GTHREAD_RECURSIVE_MUTEX_INIT
__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
as above, but for a recursive mutex.
The threads interface must define the following static functions:
int __gthread_once (__gthread_once_t *once, void (*func) ())
int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
int __gthread_key_delete (__gthread_key_t key)
int __gthread_key_delete (__gthread_key_t key)
void *__gthread_getspecific (__gthread_key_t key)
int __gthread_setspecific (__gthread_key_t key, const void *ptr)
int __gthread_mutex_destroy (__gthread_mutex_t *mutex);
int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex);    int __gthread_mutex_lock (__gthread_mutex_t *mutex);
int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);    int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);  The following are supported in POSIX threads only. They are required to
fix a deadlock in static initialization inside libsupc++. The header file
gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra    features are supported.
Types:
__gthread_cond_t
Macros:
__GTHREAD_COND_INIT
__GTHREAD_COND_INIT_FUNCTION
Interface:
武夷菌素
int __gthread_cond_broadcast (__gthread_cond_t *cond);
int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex);    int __gthread_cond_wait_recursive (__gthread_cond_t *cond,
__gthread_recursive_mutex_t *mutex);
All functions returning int should return zero on success or the error
number.  If the operation is not supported, -1 is returned.
If the following are also defined, you should
#define __GTHREADS_CXX0X 1
to enable the c++0x thread library.
Types:
电动机的单片机控制
__gthread_t
__gthread_time_t
Interface:
ifc
int __gthread_create (__gthread_t *thread, void *(*func) (void*),
void *args);
int __gthread_join (__gthread_t thread, void **value_ptr);
int __gthread_detach (__gthread_t thread);
int __gthread_equal (__gthread_t t1, __gthread_t t2);
__gthread_t __gthread_self (void);
int __gthread_yield (void);
int __gthread_mutex_timedlock (__gthread_mutex_t *m,
const __gthread_time_t *abs_timeout);
int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m,
const __gthread_time_t *abs_time);
int __gthread_cond_signal (__gthread_cond_t *cond);
int __gthread_cond_timedwait (__gthread_cond_t *cond,
__gthread_mutex_t *mutex,
const __gthread_time_t *abs_timeout);
*/

本文发布于:2024-09-21 16:40:34,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/264784.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:编译   源码   下载   步骤   依赖   过程   环境
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议