GCC:自身编译总结

148 篇文章 ¥59.90 ¥99.00
本文介绍了GCC的自我编译过程,包括参考链接、必备软件安装、编译顺序、配置选项如--enable-threads和--disable-multilib。在编译过程中,遇到的错误提示可能表明系统缺少32位开发库,可以通过重新配置并指定--enable-multilib或--disable-multilib来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考

https://gcc.gnu.org/wiki/InstallingGCC

需要了解的gcc bug

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90878

必要软件

dnf install gmp-devel.x86_64
dnf install libmpc-devel.x86_64
dnf install mpfr.x86_64
dnf install mpfr-devel.x86_64
dnf install texinfo

顺序

./configure CFLAGS=“-g -O0” --prefix=$HOME/GCC-4.6.2 --enable-languages=c,c++ --disable-multilib
make -j 4
host-x86_64-pc-linux-gnu/stage1-gcc/cc1 //编译器在这里
如果是自己建立的目录build,cc1在目录:build/gcc下;

-v

编译器自身的编译参数

gcc -v

sg built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: …/configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
–with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix

编译选项

enable_threads

这个在gcc/configure文件又解析该文件
target_thread_file 变量设置成参数值,例如 --enable-threads=posix; target_thread_file = “posix”
thread_file = “poxis”

然后在 /libgcc/configure 文件种有用到这个文件变量

# Map from thread model to thread header.
case $target_thread_file in
    aix)	thread_header=config/rs6000/gthr-aix.h ;;
    dce)	thread_header=config/pa/gthr-dce.h ;;
    lynx)	thread_header=config/gthr-lynx.h ;;
    mipssde)	thread_header=config/mips/gthr-mipssde.h ;;
    posix)	thread_header=gthr-posix.h ;;         、、、如果是posix,使用的头文件是gthr-posix.h
    rtems)	thread_header=config/gthr-rtems.h ;;
    single)	thread_header=gthr-single.h ;;
    tpf)	thread_header=config/s390/gthr-tpf.h ;;
    vxworks)	thread_header=config/gthr-vxworks.h ;;
    win32)	thread_header=config/i386/gthr-win32.h ;;
esac

走到这里,下面两个宏定义就设置上了
#define __GTHREADS 1
#define __GTHREADS_CXX0X 1

错误–disable-multilib.

/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find /lib/libgcc_s.so.1
collect2: error: ld returned 1 exit status
configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.
这个是是否支持32位程序编译。

top

[root@RH8-LCP ~]# top
top - 00:08:55 up 34 days, 22:28,  3 users,  load average: 4.02, 3.95, 3.21
Tasks: 134 total,   5 running, 129 sleeping,   0 stopped,   0 zombie
%Cpu0  : 97.0 us,  2.7 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.3 hi,  0.0 si,  0.0 st
%Cpu1  : 96.3 us,  3.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.7 hi,  0.0 si,  0.0 st
%Cpu2  : 96.0 us,  3.3 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.3 hi,  0.3 si,  0.0 st
%Cpu3  : 97.7 us,  1.3 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.7 hi,  0.3 si,  0.0 st
MiB Mem :   7685.2 total,   1238.1 free,    470.9 used,   5976.2 buff/cache
MiB Swap:   2047.0 total,   2038.1 free,      8.9 used.   6902.3 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 842082 root      20   0  179032 142820  38748 R  99.0   1.8   0:06.90 cc1plus
 842092 root      20   0  127320  80336  28316 R  77.7   1.0   0:02.34 cc1plus
 842097 root      20   0  107940  61136  27952 R  35.5   0.8   0:01.07 cc1plus
 842102 root      20   0  109256  58388  24564 R  18.6   0.7   0:00.56 cc1plus
 842034 root      20   0   51740   4072   3456 R   0.3   0.1   0:00.05 top
      1 root      20   0  241220  13404   8432 S   0.0   0.2   0:58.19 systemd

uninstall

Please note that GCC does not support ‘make uninstall’ and probably won’t do so in the near future as this would open a can of worms. Instead, we suggest that you install GCC into a directory of its own and simply remove that directory when you do not need that specific version of GCC any longer, and, if shared libraries are installed there as well, no more binaries exist that use them.
根据gcc的文档,没有提供 make uninstall 命令,说是可能引起更多其他问题。最好设置一个目录。

默认的安装路径是:/usr/local/bin
如果想uninstall,可以把这个目录下相关的二进制文件删除掉。
因为这个path的优先级要比/usr/bin的优先级高一些。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mzhan017

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值