ubuntu-toolchain-r-ubuntu-test工具链

Ethereal Lv4

1. 安装最新版本工具链

1.1 直接添加源

1
sudo add-apt-repository ppa:ubuntu-toolchain-r/test

1.2 检查libc版本

要求libc6 (>= 2.38),但是22为2.35

22需要进行额外操作如下:(注意,可能导致严重后果!

1
2
3
4
5
6
# 编辑/etc/
sudo vim /etc/apt/sources.list
## 添加如下
## deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble main restricted
# 更新glibc
sudo apt upgrade libc6

1.3 修改为最新版本

编辑文件

1
2
# 最后的文件名取决于版本
sudo vim /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-noble.sources

将文件修改为如下(24及以上版本):

其中URIs的修改帮助国内正常使用,Suites采用最新版本,可以详见选择合适的版本后出现的结果Toolchain test builds : “PPA for Ubuntu Toolchain Uploads (restricted)” team

1
2
3
4
5
Types: deb
# URIs: https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu/
URIs: https://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu/
Suites: plucky
Components: main

24以下版本修改为:

1
deb https://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu/ plucky main

1.4 cmake更新

参考Kitware APT Repository

1.4.1 添加密钥

1
2
3
4
sudo apt-get update
sudo apt-get install ca-certificates gpg wget
test -f /usr/share/doc/kitware-archive-keyring/copyright ||
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null

1.4.2 添加源

1
2
3
4
5
6
# 对于24版本
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt-get update
# 对于22版本
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt-get update

1.4.3 安装

1
sudo apt-get install cmake

1.5 离线下载

通过apt下载

首先下载解析依赖的工具

1
sudo apt install apt-rdepends

下载

1
2
apt download $(apt-rdepends g++-15 | grep -v "^ ")
apt download $(apt-rdepends cmake | grep -v "^ ")

2. 使用

2.1 更新与下载

要求libc6 (>= 2.38),但是22默认为2.35

1
sudo apt update && sudo apt install g++-15 gcc-15

2.2 创建示例文件

文件内容如下:

1
2
3
4
5
import std;

int main(){
std::cout<<"hello world";
}

2.3 编译标准库

1
g++-15 -std=c++23 -fmodules -O2 -c -fmodule-only -fsearch-include-path bits/std.cc

2.4 编译最终文件

1
g++-15 test.cpp -fmodules-ts  -std=c++23

2.5 运行

1
2
3
./a.out
# 输出如下:
# hello world

2.6 使用CMake

CMake文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cmake_minimum_required(VERSION 4.0)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "a9e1cf81-9932-4810-974b-6eccaf14e457")
set(CMAKE_C_COMPILER /usr/bin/gcc-15)
set(CMAKE_CXX_COMPILER /usr/bin/g++-15)
add_compile_options(-c)
project(Example LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_MODULE_STD 1)
# Add your source files here
set(SOURCES
test.cpp
# Add more source files if needed
)

# Add your header files here
set(HEADERS
# Add your header files here
)

add_executable(Example ${SOURCES} ${HEADERS})
#target_sources(Example
# PUBLIC
# FILE_SET cxx_modules TYPE CXX_MODULES
#)

首先要拷贝标准库文件(可能是Bug)

1
2
sudo mkdir -p /usr/lib/gcc/x86_64-linux-gnu/include/c++/
sudo cp -r /usr/include/c++/15/ /usr/lib/gcc/x86_64-linux-gnu/include/c++/

然后编译

1
2
cmake .. -G Ninja
ninja

随后运行即可

3. 其他

3.1 引用的libc库

可以通过以下命令查看:

1
ldd /usr/bin/g++-15

输出为:

1
2
3
4
ldd /usr/bin/g++-15
linux-vdso.so.1 (0x00007ffff1fe6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000749be9a00000)
/lib64/ld-linux-x86-64.so.2 (0x0000749be9dfc000)

而自带的g++-13输出为:

1
2
3
4
ldd /usr/bin/g++
linux-vdso.so.1 (0x00007ffdff98b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000791544a00000)
/lib64/ld-linux-x86-64.so.2 (0x0000791544d9a000)

3.2 编译时引用的标准库

位于/usr/lib/gcc/x86_64-linux-gnu/15

4. CMake 4.0

CMake 4.0 Release Notes — CMake 4.0.2 Documentation

基本没有特别针对modules进行改动,仍然是实验特性。

介绍视频如下:

CMake 4.0: What You Need to Know

参考

VSCODE的环境配置问题:gcc: fatal error: cannot execute ‘cc1’: spawn: No such file or directory_gcc: fatal error: cannot execute ‘cc1’: spawn: no -CSDN博客

为研究C++20语法,在ubuntu22上安装支持g++13和gcc13 - 杰之行 - 博客园

在ubuntu中安装较新版本的gcc和gdb - 及途又八 - 博客园

Linux编译安装GCC 15的方法 - 哔哩哔哩

为研究C++20语法,在ubuntu22上安装支持g++13和gcc13 - 杰之行 - 博客园

Toolchain test builds : “PPA for Ubuntu Toolchain Uploads (restricted)” team

GCC 15 Release Series — Changes, New Features, and Fixes - GNU Project

Toolchain test builds : “PPA for Ubuntu Toolchain Uploads (restricted)” team

[xim+]: 最新gcc15.1.0发布, 一键从源码构建 – c++23 import std启动 | D2learn Forum

升级libstdc++、libgcc_s.so、libc.so.6 - 邶风 - 博客园

[ubuntu20.04升级GLIBC高版本方法,解决:version `GLIBC_2.34‘ not found_缺少多个 glibc 版本,包括 glibc 2.32、glibc 2.33、glibc 2.34 -CSDN博客](https://blog.csdn.net/shelutai/article/details/132363838 )

Kitware APT Repository

ubuntu2004升级cmake版本到4.0.1 – 运维术

Ubuntu 安装、升级最新cmake的几种方法 - 今夜白的学习笔记

c++ 20 module 模块使用 cmake_cmake module-CSDN博客

CMake 配置 C++ Modules | FlyAndNotDown Blog

CMake/XMake C++ Module实践 - 知乎

(6 封私信 / 80 条消息) Cmake支持C++20 modules了吗? - 知乎

CMake 4.0 Release Notes — CMake 4.0.2 Documentation

CMAKE_EXECUTE_PROCESS_COMMAND_ERROR_IS_FATAL — CMake 4.0.2 Documentation

cmake-cxxmodules(7) — CMake 4.0.2 Documentation

2025年c++import std使用 - 知乎

Strange errors while build example with Import std on main branch - Development - CMake Discourse

Strange errors while build example with Import std on main branch - Development - CMake Discourse

使用 gcc-15 导入 std 模块 - c++ - SO中文参考 - www.soinside.com

如何使用CMake构建一个使用C++23标准库模块(导入std)的项目? c++-modules - Dev59

import std in CMake 3.30

2025年c++import std使用 - 知乎

CMake 4.0: What You Need to Know

Cmake 4.0.0 发布,开源构建系统 - OSCHINA - 中文开源技术交流社区

CMAKE_CXX_MODULE_STD — CMake 4.0.2 Documentation

  • Title: ubuntu-toolchain-r-ubuntu-test工具链
  • Author: Ethereal
  • Created at: 2025-06-04 15:23:13
  • Updated at: 2025-06-05 12:21:32
  • Link: https://ethereal-o.github.io/2025/06/04/ubuntu-toolchain-r-ubuntu-test工具链/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments