龙芯3A5000下最新gcc 12.1交叉编译器获取与使用

    本来这篇文章是要写成自己如何一步步编译成功gcc12.1的,无论是在龙芯35000下编译还是在x86机器下构建交叉编译工具链,折腾到最后,gcc12.1倒是编译出来了,glibc不知道应该怎么搞,最后发现龙芯官方github里面有人编译好了gcc12.1 ,下载地址:

https://github.com/sunhaiyong1978/CLFS-for-LoongArch

https://github.com/loongson/build-tools    

可以直接从第一个下载链接里面去下载完整的交叉编译工具链,然后放到x86 linux下面使用,使用之前配置一下环境变量

vi ~/.bashrc

export PATH=/phx/cross-tools/bin:$PATH
export LD_LIBRARY_PATH=/phx/cross-tools/lib:$LD_LIBRARY_PATH
export CROSS_COMPILE=loongarch64-linux-

  然后编译:

loongarch64-unknown-linux-gnu-gcc -o test1 test.c -static

  复制test1 到龙芯机器里面可以正常运行。

然后再说一下自己编译的折腾过程记录:

sudo apt update
sudo apt install  texinfo autoconf automake libiberty-dev sed flex bison gzip gettext  libelf-dev libgomp1 make tar libgmp-dev libmpfr-dev libmpc-dev libisl-dev build-essential -y

我最后是在debian 11下面编译的,注意必须安装以上gcc编译依赖,特别是texinfo等,编译binutils的时候这都是必须要用的。

 下面是从github找的一个编译脚本,我修改了gcc 12.1的checksum等

#!/usr/bin/env python3
""" Cross-compiler toolchain build script

    Possible target platforms are:
     aarch64    ARM64
     amd64      AMD64 (x86-64, x64)
     arm32      ARM
     ia32       IA-32 (x86, i386)
     ia64       IA-64 (Itanium)
     mips32     MIPS little-endian 32b
     mips32eb   MIPS big-endian 32b
     mips64     MIPS little-endian 64b
     ppc32      32-bit PowerPC
     ppc64      64-bit PowerPC
     sparc32    SPARC V8
     sparc64    SPARC V9
     lm32       LatticeMico32

    The toolchain is installed into directory specified by the
    CROSS_PREFIX environment variable. If the variable is not
    defined, /usr/local/cross/ is used as default.

    If '--install no' is present, the toolchain still uses the
    CROSS_PREFIX as the target directory but the installation
    copies the files into PKG/ subdirectory without affecting
    the actual root file system. That is only useful if you do
    not want to run the script under the super user."""

# Copyright (c) 2016-2020 Konstantin Tcholokachvili
# All rights reserved.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Credits:
# This script is inspired by toolchain.sh made by Martin Decky for HelenOS
# project.

import os
import sys
import ftplib
import shutil
import pathlib
import tarfile
import hashlib
import tempfile
import argparse
import subprocess


# Toolchain versions
BINUTILS_VERSION = '2.38'
GCC_VERSION = '12.1.0'
GDB_VERSION = '12.1'

BASEDIR = os.getcwd()
BINUTILS_TARBALL = 'binutils-{}.tar.xz'.format(BINUTILS_VERSION)
GCC_TARBALL = 'gcc-{}.tar.xz'.format(GCC_VERSION)
GDB_TARBALL = 'gdb-{}.tar.xz'.format(GDB_VERSION)

INSTALL_DIR = BASEDIR + '/PKG'

BINUTILS_CHECKSUM = '6e39cad1bb414add02b5b1169c18fdc5'
GCC_CHECKSUM = 'ed45b55ee859ada4b25a1e76e0c4d966'
GDB_CHECKSUM = '759a1b8d2b4d403367dd0e14fa04643d'

GMP_MAIN = """
#define GCC_GMP_VERSION_NUM(a, b, c) \
        (((a) << 16L) | ((b)

你可能感兴趣的:(IT技术相关,gnu,linux,服务器)