我正在尝试在以下 Rust docker 映像中安装 gcc13 和 g++13。
# Builder
FROM rust:1-bookworm AS builder
RUN apt update
RUN apt install software-properties-common -y
RUN apt-get install python3-launchpadlib -y
RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
RUN apt update
RUN apt install -y clang g++-13 gcc-13
由于 gcc13 在 debian bookworm 中本身不可用,我已经尝试使用类似使用
ppa:ubuntu-toolchain-r/test
的方法,如here所述。
但是,我仍然收到错误
E: Unable to locate package g++-13
和E: Unable to locate package g++-13
。有什么想法我做错了什么吗?
选项 1:阿尔卑斯山
您可以使用 Alpine 基础镜像。
FROM rust:1-alpine
RUN apk add g++
在这种情况下,您将立即可以访问 GCC 13。
/ # gcc -v
gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
/ # g++ -v
gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
选项 2:安装到 Debian
如果您确实想要基于 Debian Bookworm 的映像,那么您可以从源代码安装 GCC 13。这有点困难,因为构建需要一段时间。
FROM rust:1-bookworm
RUN apt-get update && \
apt-get install -y \
build-essential \
wget \
libgmp-dev \
libmpfr-dev \
libmpc-dev && \
rm -rf /var/lib/apt/lists/*
RUN wget -q https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
RUN tar -xf gcc-13.2.0.tar.gz && \
cd gcc-13.2.0 && \
./contrib/download_prerequisites
# This will cross-compile using the existing GCC on the image.
RUN cd gcc-13.2.0 && \
./configure --disable-multilib --enable-languages=c,c++ && \
make -j$(nproc) && \
make install
RUN rm -rf gcc-13.2.0.tar.gz gcc-13.2.0
RUN update-alternatives \
--install /usr/bin/gcc gcc /usr/local/bin/gcc-13 60 \
--slave /usr/bin/g++ g++ /usr/local/bin/g++-13