<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Soul Of Free Loop &#187; gcc</title>
	<atom:link href="https://zohead.com/archives/tag/gcc/feed" rel="self" type="application/rss+xml" />
	<link>https://zohead.com</link>
	<description>Uranus Zhou&#039;s Blog</description>
	<lastBuildDate>Sat, 19 Jul 2025 15:42:46 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8</generator>
	<item>
		<title>使用Software Collections编译最新Linux kernel</title>
		<link>https://zohead.com/archives/scl-linux-kernel/</link>
		<comments>https://zohead.com/archives/scl-linux-kernel/#comments</comments>
		<pubDate>Thu, 07 Sep 2017 16:08:52 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[binutils]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[Software Collections]]></category>

		<guid isPermaLink="false">https://zohead.com/?p=1502</guid>
		<description><![CDATA[关于 Software Collections 使用 Software Collections（SCL）的契机是最近我需要在 CentOS 6 系统上编译最新版本的 Linux kernel，主要用于测试 Btrfs 的数据校验对于 AVX2 指令的支持情况。然而大家都知道 CentOS 6 自带的软件包版本都是非常老的，glibc 维持在 2.12 版本，老的 gcc 4.4 版本则根本就不支持 AVX2 指令，这样编译 Linux kernel 时会自动关闭 async xor 对 AVX2 的支持。 如果要自己动手编译新版本 gcc，这感觉还是有点吃力不讨好，幸好 Red Hat 也注意 [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2 id="about-scl">关于 Software Collections</h2>
<p>使用 Software Collections（SCL）的契机是最近我需要在 CentOS 6 系统上编译最新版本的 Linux kernel，主要用于测试 Btrfs 的数据校验对于 AVX2 指令的支持情况。然而大家都知道 CentOS 6 自带的软件包版本都是非常老的，glibc 维持在 2.12 版本，老的 gcc 4.4 版本则根本就不支持 AVX2 指令，这样编译 Linux kernel 时会自动关闭 async xor 对 AVX2 的支持。</p>
<p>如果要自己动手编译新版本 gcc，这感觉还是有点吃力不讨好，幸好 Red Hat 也注意到这个问题了，我们可以通过 Software Collections 实现在一个系统上安装多个版本的开发工具或者运行环境，仓库里高版本的软件包通常都是由 Red Hat 维护的，比较常见的需求例如将 CentOS 6 自带的 Python 升级为 2.7 版本。</p>
<p>大家可以访问 Software Collections 官网了解更多信息：</p>
<p><a href="https://www.softwarecollections.org/en/" target="_blank">https://www.softwarecollections.org/en/</a></p>
<h2 id="install-scl-gcc">安装 gcc 新版本</h2>
<p>首先需要安装 SCL 支持，CentOS 6 通过 yum 安装还是非常简单的：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# yum install centos-release-scl
Dependencies Resolved

================================================================
 Package              Arch    Version            Repository Size
================================================================
Installing:
 centos-release-scl   noarch  10:7-3.el6.centos  extras     12 k

Transaction Summary
================================================================
Install       1 Package(s)

Total download size: 12 k
Installed size: 19 k
Is this ok [y/N]: y
Downloading Packages:
centos-release-scl-7-3.el6.centos.noarch.rpm | 12 kB    00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 10:centos-release-scl-7-3.el6.centos.noarch
duration: 120(ms)
Installed products updated.

Installed:
  centos-release-scl.noarch 10:7-3.el6.centos                               

Complete!
</pre>
<p>然后安装 SCL 工具：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# yum install scl-utils scl-utils-build
</pre>
<p>运行 <code>yum makecache</code> 更新缓存之后，就可以查找 SCL 提供了哪些新版本的 gcc 和 binutils 包了：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# yum list | grep -E &quot;devtoolset-.*-(gcc|binutils)&quot;
devtoolset-3-binutils.x86_64                2.24-18.el6           centos-sclo-rh
devtoolset-3-binutils-devel.x86_64          2.24-18.el6           centos-sclo-rh
devtoolset-3-gcc.x86_64                     4.9.2-6.2.el6         centos-sclo-rh
devtoolset-3-gcc-c++.x86_64                 4.9.2-6.2.el6         centos-sclo-rh
devtoolset-3-gcc-gfortran.x86_64            4.9.2-6.2.el6         centos-sclo-rh
devtoolset-3-gcc-plugin-devel.x86_64        4.9.2-6.2.el6         centos-sclo-rh
devtoolset-4-binutils.x86_64                2.25.1-8.el6          centos-sclo-rh
devtoolset-4-binutils-devel.x86_64          2.25.1-8.el6          centos-sclo-rh
devtoolset-4-gcc.x86_64                     5.3.1-6.1.el6         centos-sclo-rh
devtoolset-4-gcc-c++.x86_64                 5.3.1-6.1.el6         centos-sclo-rh
devtoolset-4-gcc-gdb-plugin.x86_64          5.3.1-6.1.el6         centos-sclo-rh
devtoolset-4-gcc-gfortran.x86_64            5.3.1-6.1.el6         centos-sclo-rh
devtoolset-4-gcc-plugin-devel.x86_64        5.3.1-6.1.el6         centos-sclo-rh
devtoolset-6-binutils.x86_64                2.27-8.el6            centos-sclo-rh
devtoolset-6-binutils-devel.x86_64          2.27-8.el6            centos-sclo-rh
devtoolset-6-gcc.x86_64                     6.2.1-3.1.el6         centos-sclo-rh
devtoolset-6-gcc-c++.x86_64                 6.2.1-3.1.el6         centos-sclo-rh
devtoolset-6-gcc-gdb-plugin.x86_64          6.2.1-3.1.el6         centos-sclo-rh
devtoolset-6-gcc-gfortran.x86_64            6.2.1-3.1.el6         centos-sclo-rh
devtoolset-6-gcc-plugin-devel.x86_64        6.2.1-3.1.el6         centos-sclo-rh
</pre>
<p>可以看到 SCL 提供了 4.9.2、5.3.1、6.2.1 这几个新版本的 gcc 支持，与 binutils 一起分别属于几个不同版本的 devtoolset 软件包。</p>
<p>初步确认 gcc 5.3.1 就可以支持 AVX2 指令，因此直接安装对应 devtoolset-4 版本的 gcc 和 binutils 软件包：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# yum install devtoolset-4-gcc.x86_64 devtoolset-4-binutils.x86_64
</pre>
<h2 id="use-scl">使用 SCL</h2>
<p>软件包安装完成之后，我们可以使用 <code>scl -l</code> 命令查看 SCL 安装的软件包列表：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# scl -l
devtoolset-4
python27
</pre>
<p>当然 SCL 并不会直接替换系统自带的老版本软件包，需要通过 scl 命令切换使用：</p>
<pre class="brush: bash; title: ; notranslate">
scl enable &lt;scl-package-name&gt; &lt;command&gt;
</pre>
<p>这样我想开启一个使用新版本 gcc 的 shell，直接运行命令：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# scl enable devtoolset-4 bash
</pre>
<p>这样会启动一个新的 bash shell，可以在其中看到 gcc 已经是新的 5.3.1 版本了：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# gcc --version
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
</pre>
<p>当然如果不想开启新的 shell，也可以进入 Linux kernel 源代码目录直接使用新版本 gcc 来编译：</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~/linux-4.10]# scl enable devtoolset-4 make
</pre>
<p>最后提醒一下 Software Collections 的软件包是可以不安装直接在线搜索的哦，从 SCL 官网的 collections 里就可以搜索：</p>
<p><a href="https://www.softwarecollections.org/en/scls/" target="_blank">https://www.softwarecollections.org/en/scls/</a></p>
<p>搜索结果里就会有 SCL 软件包的安装方法，例如 Python 2.7 搜索到之后直接运行 <code>yum install python27</code> 就可以安装使用了，祝大家玩的开心。</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/scl-linux-kernel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
