Newer version of gcc for Torizon IDE Extension for better C++ 20 support?

I’m currently using v2.6.2 of the Torizon IDE Extension for Visual Studio Code.
I noticed that some of the features of the standard library for C++ 20 are not supported even though __cplusplus is set to 202002 which would normally indicate C++ 20. For example I tried to use the time zone support in std::chrono::time_zone but that is not supported.

It looks like the container which the extension uses to build the code uses gcc v12.2.0.
and it appears that the newest version available is v13.3.1.
Is it possible to update the version of gcc used by the build container?
Arm GNU Toolchain Downloads – Arm Developer

However, this page suggests that full support of C++ 20 might require gcc 14
So I might be out of luck for now if gcc 14 has not yet been ported to arm
Compiler support for C++20 - cppreference.com

I also tried using the date library which implemented some of these features for C++ 17, but that library does not seem to work well with the version of gcc used with Torizon
HowardHinnant/date: A date and time library based on the C++11/14/17 header (github.com)

Has anyone had any luck getting either the time_zone library in C++ 20 or the older date library to work?

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


To address your issue with the C++20 support in the Torizon IDE Extension for Visual Studio Code, here are some steps and considerations:

  1. Current GCC Version: As you mentioned, the current build container uses GCC v12.2.0. While this version does support many C++20 features, it may not fully support all of them, such as std::chrono::time_zone.

  2. Updating GCC Version: You can attempt to update the GCC version in your build container. This involves creating a custom Dockerfile that installs the desired version of GCC. Here’s a basic example of how you might do this:

    FROM torizon/debian-cross-toolchain-arm64:2-bullseye
    
    # Install dependencies
    RUN apt-get update && apt-get install -y \
        build-essential \
        wget \
        && rm -rf /var/lib/apt/lists/*
    
    # Download and install GCC 13.3.1
    RUN wget https://ftp.gnu.org/gnu/gcc/gcc-13.3.1/gcc-13.3.1.tar.gz \
        && tar -xzf gcc-13.3.1.tar.gz \
        && cd gcc-13.3.1 \
        && ./contrib/download_prerequisites \
        && mkdir build && cd build \
        && ../configure --enable-languages=c,c++ --disable-multilib \
        && make -j$(nproc) \
        && make install
    
    # Set the new GCC as the default
    RUN update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/gcc 60 \
        && update-alternatives --install /usr/bin/g++ g++ /usr/local/bin/g++ 60
    

    This Dockerfile starts from a base Torizon image and installs GCC 13.3.1. You can build this Dockerfile and use the resulting image as your build container.

  3. Using the Custom Container in Torizon IDE:

    • In your VS Code project, update the devcontainer.json to use your custom Docker image.
    • Ensure that your project settings in the Torizon IDE extension point to this new container.
  4. Limitations and Future Support: As you noted, full support for C++20 might require GCC 14, which may not yet be available for ARM. Keep an eye on updates from the GCC project and the Torizon team for newer toolchain support.

  5. Alternative Libraries: If updating GCC does not resolve your issue, you might need to look for alternative libraries or workarounds. The date library you mentioned is a good fallback, but compatibility issues might arise with different GCC versions.

  6. Community and Support: Engage with the Toradex community and support channels. Other developers might have faced similar issues and could offer solutions or workarounds.

By following these steps, you should be able to update the GCC version in your build container and potentially resolve the issues with C++20 support. If GCC 14 becomes available, you can follow a similar process to update to that version.

Please, also check if these links can help you solve your problem:

Set up the Torizon IDE Extension Environment | Toradex Developer Center.

Greetings @MikeS,

Our containers are Debian-based, therefore we simply use whatever version of GCC is available in Debian at the time. For Debian Bookworm that is GCC 12.2.0 as you said: Debian -- Details of package g++-aarch64-linux-gnu in bookworm

If you want another version of GCC you’ll need to customize the container with versions of things you require for your needs. Our containers are meant to be a starting point reference. They can always be customized for more specific needs. Have you tried substituting a different version of GCC to see if it fulfills your requirements?

Best Regards,
Jeremias

Just checking-in. Were you able to try a newer version of GCC in the container and see if that resolves your requirement?

Best Regards,
Jeremias

Hi @jeremias.tx,

I did try to use a newer version of GCC in the container, but I couldn’t figure out how to do it. So, I changed my strategy to avoid using the newer parts of the standard library. That means I am OK for now and I can just wait till the container we use is updated to the next version of Debian at some point in the future.

If you want to give me some pointers about how to use a newer version of GCC then I’d be happy to try it and report back.

Mike

If you want to give me some pointers about how to use a newer version of GCC then I’d be happy to try it and report back.

Well I’m not sure there’s any specific pointers really. A container is simply a sandbox environment. Building and installing a different version of gcc in a container would be a similar process to doing it on a non-container environment. There are generic instructions on installing gcc from their website here: Installing GCC - GNU Project

I imagine you would just need to do this process, but in a container. Now obviously Debian uses a specific version of gcc in it’s package feed for a reason. Venturing outside of these tested versions always has a “at your own risk” associated with it.

Best Regards,
Jeremias

@jeremias.tx, I did try to follow those steps already but I encountered errors while attempting to build gcc in the container. At that point I decided it probably wasn’t worth going further down this path as I can work around the library limitations. I think we can close this ticket.

Hey @MikeS,
I tried it locally (I use a newer GCC from time to time due to C++ support as well) and following the GNU Project instructions it worked well. Note that it can take a while to build.

FROM debian:bookworm-slim AS build

ENV GCC_VERSION=gcc-14.2.0
ENV GCC_URL=https://ftp.gnu.org/gnu/gcc/${GCC_VERSION}/${GCC_VERSION}.tar.gz
ENV LD_LIBRARY_PATH="/usr/local/gcc-14/lib64"

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ca-certificates \
    wget \
    curl \
    git \
    libgmp-dev \
    libmpfr-dev \
    libmpc-dev \
    flex \
    bison \
    libisl-dev \
    zlib1g-dev \
    libzstd-dev \
    libatomic1 \
    libgcc-12-dev \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/src/gcc && \
    cd /usr/src/gcc && \
    wget ${GCC_URL} && \
    tar -xf ${GCC_VERSION}.tar.gz && \
    rm ${GCC_VERSION}.tar.gz

    RUN cd /usr/src/gcc/${GCC_VERSION} && \
    ./contrib/download_prerequisites && \
    mkdir build && cd build && \
    ../configure --prefix=/usr/local/gcc-14 --enable-languages=c,c++ --disable-multilib && \
    make -j$(nproc) && \
    make install

FROM debian:bookworm-slim AS release

ENV PATH="/usr/local/gcc-14/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/gcc-14/lib64"

COPY --from=build /usr/local/gcc-14 /usr/local/gcc-14

RUN apt-get update && apt-get install -y --no-install-recommends \
    libgmp10 \
    libmpfr6 \
    libmpc3 \
    libisl23 \
    libatomic1 \
    zlib1g \
    libzstd1 \
    libgcc-s1 \
    libstdc++6 \
    && rm -rf /var/lib/apt/lists/*
1 Like