Linux 多架构支持介绍和实践
1. Linux 上多架构支持指的是什么意思?
在Linux 上开启多架构支持(multi-arch support),指的是可以让您在同一系统上安装多个不同架构的软件包,这在交叉编译的场景显得格外重要。
以下实际操作均在Ubuntu 18.04 + x86_64 环境下演示。
2. 如何查看和开启多架构支持?
2.1 查看
[netease@netease-Precision-3630-Tower ~]$ dpkg --print-foreign-architectures
i386
以上说明该系统支持的架构包括自身(x86_64)+ i386(x86)
2.2 开启arm64架构支持
[netease@netease-Precision-3630-Tower ~]$ sudo dpkg --add-architecture arm64
[netease@netease-Precision-3630-Tower ~]$ dpkg --print-foreign-architectures
i386
arm64
3. 如何安装多架构软件
以安装x86_64和arm64架构的OpenGL为例。
3.1 修改apt源
使用清华大学镜像源。
3.1.1 32/64位x86架构包
ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
3.1.2 其他架构包 (arm64等)
ubuntu-ports | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
最终修改/etc/apt/sources.list, 如下, 支持下载amd64(x86_64)和arm64两种架构的包。
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb [arch=arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
# # deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
3.2 安装包
3.2.1 x86_64
sudo apt-get update
sudo apt-get install libgl1-mesa-dev 或者sudo apt-get install libgl1-mesa-dev:amd64
3.2.2 arm64
sudo apt-get update
sudo apt-get install libgl1-mesa-dev:arm64