我正在 ARM 上开发嵌入式 RTOS,现在我要在我的 X86 Linux 主机(ubuntu-20.04)中为 ARM 构建 GNU 工具链,所以我参考了以下内容https://gnutoolchains.com/building/
- 下载 binutils-2.42.tar.gz
- 下载gcc-11.3.0.tar.gz
- 下载newlib-4.4.0-20231231
- 下载 mpc-1.0.3.tar.gz
- 下载mpfr-3.1.6.tar.bz2
- 下载gmp-4.3.2.tar.bz2
- 下载gdb-14.1.tar.gz
将它们解压到/home/t/testmnt/armtoolchain/中,如下,
@t-VirtualBox:~/testmnt/armtoolchain$ ls -l
total 442348
drwxrwx--- 20 t t 4096 3月 21 09:11 binutils-2.42
drwxrwx--- 13 t t 4096 3月 23 18:06 binutils-2.42-build
-rwxrwx--- 1 t t 51892456 1月 29 23:22 binutils-2.42.tar.gz
drwxrwx--- 38 t t 4096 4月 21 2022 gcc-11.3.0
drwxrwx--- 16 t t 4096 3月 23 19:56 gcc-11.3.0-build
-rwxrwx--- 1 t t 143527306 4月 21 2022 gcc-11.3.0.tar.gz
drwxrwxr-x 23 t t 4096 3月 22 12:47 gdb-14.1
drwxrwxr-x 17 t t 4096 3月 22 12:53 gdb-14.1-build
-rw-rw-r-- 1 t t 41058403 12月 3 13:39 gdb-14.1.tar.gz
drwxrwx--- 16 t t 4096 3月 21 10:37 gmp-4.3.2
-rwxrwx--- 1 t t 1897483 2月 1 2010 gmp-4.3.2.tar.bz2
drwxrwx--- 6 t t 4096 3月 21 10:42 mpc-1.0.3
-rwxrwx--- 1 t t 669925 4月 28 2016 mpc-1.0.3.tar.gz
drwxrwx--- 9 t t 4096 3月 21 10:46 mpfr-3.1.6
-rwxrwx--- 1 t t 1287202 9月 7 2017 mpfr-3.1.6.tar.bz2
drwxrwx--- 9 t t 4096 3月 22 08:05 newlib-4.4.0.20231231
drwxrwxr-x 4 t t 4096 3月 22 14:27 newlib-4.4.0.20231231-build
drwxrwx--- 6 t t 4096 3月 23 18:07 out
我首先配置并构建了 gmp、mpc 和 mpfr,并将它们安装到 /usr/local/lib/
然后,我配置并构建binutils
如下,
cd binutils-2.42-build/
../binutils-2.42/configure -target arm-test-eabi --prefix /home/t/testmnt/armtoolchain/out/
make install-strip
然后,我配置并构建gcc
如下,
cd gcc-11.3.0-build/
../gcc-11.3.0/configure --target=arm-test-eabi --build=x86_64-linux-gnu --host=x86_64-linux-gnu --prefix /home/t/testmnt/armtoolchain/out --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --enable-threads=posix --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-multilib-list=aprofile,rmprofile --with-headers=/home/t/testmnt/armtoolchain/newlib-4.4.0.20231231/newlib/libc/include --with-pkgversion='GNU Arm Embedded Toolchain 11.3.0'
make -j12
然后,我遇到了以下错误。
make[4]: Entering directory '/home/t/testmnt/armtoolchain/gcc-11.3.0-build/arm-test-eabi/arm/v5te/softfp/libgcc'
# If this is the top-level multilib, build all the other
# multilibs.
/home/t/testmnt/armtoolchain/gcc-11.3.0-build/./gcc/xgcc -B/home/t/testmnt/armtoolchain/gcc-11.3.0-build/./gcc/ -B/home/t/testmnt/armtoolchain/out/arm-test-eabi/bin/ -B/home/t/testmnt/armtoolchain/out/arm-test-eabi/lib/ -isystem /home/t/testmnt/armtoolchain/out/arm-test-eabi/include -isystem /home/t/testmnt/armtoolchain/out/arm-test-eabi/sys-include -g -O2 -marm -march=armv5te+fp -mfloat-abi=softfp -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fno-inline -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fno-inline -I. -I. -I../../../../.././gcc -I../../../../../../gcc-11.3.0/libgcc -I../../../../../../gcc-11.3.0/libgcc/. -I../../../../../../gcc-11.3.0/libgcc/../gcc -I../../../../../../gcc-11.3.0/libgcc/../include -o emutls.o -MT emutls.o -MD -MP -MF emutls.dep -fexceptions -c ../../../../../../gcc-11.3.0/libgcc/emutls.c -fvisibility=hidden -DHIDE_EXPORTS
In file included from ../../../../../../gcc-11.3.0/libgcc/gthr.h:148,
from ../../../../../../gcc-11.3.0/libgcc/emutls.c:31:
./gthr-default.h:102:9: error: 'pthread_once' undeclared here (not in a function); did you mean 'pthread_once_t'?
102 | __gthrw(pthread_once)
| ^~~~~~~~~~~~
./gthr-default.h:90:19: note: in definition of macro '__gthrw2'
90 | static __typeof(type) name \
| ^~~~
./gthr-default.h:102:1: note: in expansion of macro '__gthrw'
102 | __gthrw(pthread_once)
| ^~~~~~~
./gthr-default.h:103:9: error: 'pthread_getspecific' undeclared here (not in a function)
103 | __gthrw(pthread_getspecific)
| ^~~~~~~~~~~~~~~~~~~
./gthr-default.h:90:19: note: in definition of macro '__gthrw2'
90 | static __typeof(type) name \
| ^~~~
./gthr-default.h:103:1: note: in expansion of macro '__gthrw'
103 | __gthrw(pthread_getspecific)
| ^~~~~~~
./gthr-default.h:104:9: error: 'pthread_setspecific' undeclared here (not in a function)
104 | __gthrw(pthread_setspecific)
| ^~~~~~~~~~~~~~~~~~~
./gthr-default.h:90:19: note: in definition of macro '__gthrw2'
90 | static __typeof(type) name \
| ^~~~
./gthr-default.h:104:1: note: in expansion of macro '__gthrw'
104 | __gthrw(pthread_setspecific)
| ^~~~~~~
./gthr-default.h:106:9: error: 'pthread_create' undeclared here (not in a function); did you mean 'htab_create'?
106 | __gthrw(pthread_create)
| ^~~~~~~~~~~~~~
./gthr-default.h:90:19: note: in definition of macro '__gthrw2'
90 | static __typeof(type) name \
| ^~~~
./gthr-default.h:106:1: note: in expansion of macro '__gthrw'
106 | __gthrw(pthread_create)
| ^~~~~~~
./gthr-default.h:107:9: error: 'pthread_join' undeclared here (not in a function); did you mean 'pthread_kill'?
107 | __gthrw(pthread_join)
| ^~~~~~~~~~~~
.....
.....
我检查了../newlib-4.4.0.20231231/newlib/libc/include/pthread.h
,它有以下定义,
254 /* Thread Creation, P1003.1c/Draft 10, p. 144 */
255
256 int pthread_create (pthread_t *__pthread, const pthread_attr_t *__attr,
257 void *(*__start_routine)(void *), void *__arg);
258
259 /* Wait for Thread Termination, P1003.1c/Draft 10, p. 147 */
260
261 int pthread_join (pthread_t __pthread, void **__value_ptr);
....
....
298 #define PTHREAD_ONCE_INIT _PTHREAD_ONCE_INIT
299
300 int pthread_once (pthread_once_t *__once_control,
301 void (*__init_routine)(void));
....
....
308 /* Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 */
309
310 int pthread_setspecific (pthread_key_t __key, const void *__value);
311 void * pthread_getspecific (pthread_key_t __key);
我用谷歌搜索发现了类似的问题,其中一个指出建筑系统应该有问题,但我不知道这是什么问题。
那么目前,构建gcc-11.3.0
失败enable-threads=posix
,如何修复它并使用 newlib 构建 ARM GNU 工具链?
谢谢,
答案1
仅当您拥有能够运行线程的目标操作系统时,线程支持才有意义;裸机系统上并非如此,因此以这种方式配置的 GCC 无法支持 POSIX 线程。即使有操作系统支持,还需要 newlib 和 GCC 的特定支持;看池malloc
锁定功能例如。
使用默认值(--enable-threads
根本没有选项)构建应该可以正常工作并选择适当的设置。
gcc-arm-none-eabi
请注意,如果 GCC 9 和 newlib 3.3 足够好,您可以通过在 Ubuntu 20.04 上安装该软件包来省去一些麻烦。 Ubuntu 的后续版本有更新版本的 GCC,但是newlib 4.4 尚未在 Ubuntu 中使用(它在 Debian 中可用,所以它应该在 Ubuntu 24.10 中可用)。