g++编译

Ethereal Lv5

1. 编译

Linux纯命令行以源码编译安装gcc(2024年2月5日)_源码安装gcc-CSDN博客

1.1 下载依赖

1
2
3
sudo apt install build-essential
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev
sudo apt-get install gcc-multilib g++-multilib

1.2 下载源码

1
wget -P ~ 'https://mirrors.nju.edu.cn/gnu/gcc/gcc-15.1.0/gcc-15.1.0.tar.gz'

1.3 编译

1
2
3
mkdir build && cd build
../configure --enable-multilib
make -j8

1.4 构建deb包

先创一个目录

1
mkdir ~/install

创建deb包

1
2
3
sudo make install DESTDIR=~/install  # 安装到临时目录
cd ~/install
mkdir -p DEBIAN # 创建控制目录

编写控制文件~/install/DEBIAN/control

1
2
3
4
5
6
7
8
Package: gcc-custom
Version: 15.1.0-1
Section: devel
Priority: optional
Architecture: amd64
Maintainer: Your Name <you@example.com>
Description: Custom build of GCC/G++ 15.1.0
This package provides a manually compiled version of g++.

安装脚本

1
2
3
4
5
6
7
8
9
# ~/install/DEBIAN/preinst(安装前执行)
#!/bin/sh
echo "准备安装g++自定义版..."
exit 0

# ~/install/DEBIAN/postinst(安装后执行)
#!/bin/sh
echo "安装完成!请运行g++ --version"
exit 0

执行权限

1
chmod 755 DEBIAN/preinst DEBIAN/postinst

构建

1
2
cd ~/install
dpkg-deb --build . gcc-custom_15.1.0-1_amd64.deb

验证

1
dpkg -c gcc-custom_12.3.0-1_amd64.deb  # 查看内容

1.5 安装

安装deb包

1
2
3
sudo dpkg -i gcc-custom_15.1.0-1_amd64.deb  # 测试安装
whereis g++ # /usr/local/bin/g++
/usr/local/bin/g++ --version # 检查版本

编译

1
2
/usr/local/bin/g++ -std=c++23 -fmodules -O2 -c -fmodule-only -fsearch-include-path bits/std.cc
/usr/local/bin/g++ test.cpp -fmodules-ts -std=c++23

运行(注意必须手动指定stdlibc的路径)

1
2
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
./a.out

参考

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

gcc 11.4.0版本的源码编译安装 - 知乎

GCC 源码编译安装(离线,普通用户) | Fenglielie

Linux纯命令行以源码编译安装gcc(2024年2月5日)_源码安装gcc-CSDN博客

gcc 11.4.0版本的源码编译安装 - 知乎

GCC: Anonymous read-only Git access - GNU Project

linux下deb包的管理及制作 | 一次成功 - 进击的davis - 博客园

Ubuntu-22.04离线安装gcc - 知乎

Ubuntu系统下轻松使用GCC编译Deb包全攻略 - 云原生实践

ubuntu-toolchain-r-ubuntu-test工具链 - Ethereal’s Blog

debian linux下dpkg-source:command not found-CSDN社区

第 6 章 构建软件包

在Linux安装autoconf-2.69版本_autoconf-2.69.tar.gz-CSDN博客

记录:/bin/sh: 1: lsdiff: not found-CSDN博客

Debian的loong64构造进度有点看不明白【龙芯吧】_百度贴吧

Ubuntu使用dpkg查看与修改architecture的用法 - 高宏宇 - 博客园

ubuntu安装多个版本的g++和gcc,并设置默认版本的c++和g++_ubuntu设置默认使用c++新版本-CSDN博客

GCC 15 Release Series - GNU Project

NJU Mirror

g++11编译安装+虚拟机扩容_g++ 11-CSDN博客

kubevirt入门 - Ethereal’s Blog

linux 给运行程序指定动态库路径_编译linux运行的程序-CSDN博客

  • Title: g++编译
  • Author: Ethereal
  • Created at: 2025-06-08 13:29:45
  • Updated at: 2025-06-08 17:47:53
  • Link: https://ethereal-o.github.io/2025/06/08/g-编译/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments