<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>阁下 - 组件</title>
<link>https://liar.org.cn/index.php/category/Component/</link>
<atom:link href="https://liar.org.cn/index.php/feed/category/Component/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Wed, 20 Aug 2025 02:40:00 +0000</lastBuildDate>
<pubDate>Wed, 20 Aug 2025 02:40:00 +0000</pubDate>
<item>
<title>源码编译安装GCC</title>
<link>https://liar.org.cn/index.php/2025/08/20/27.html</link>
<guid>https://liar.org.cn/index.php/2025/08/20/27.html</guid>
<pubDate>Wed, 20 Aug 2025 02:40:00 +0000</pubDate>
<dc:creator>Lewis Ho</dc:creator>
<category><![CDATA[C++]]></category>
<category><![CDATA[Linux]]></category>
<category><![CDATA[组件]]></category>
<description><![CDATA[安装依赖环境sudo dnf groupinstall &quot;Development Tools&quot; -ysudo dnf install gmp gmp-devel mpfr m...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h1>安装依赖环境</h1><pre><code class="lang-shell">sudo dnf groupinstall &quot;Development Tools&quot; -y
sudo dnf install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel isl isl-devel zlib-devel wget make bzip2 -y</code></pre><p><strong>若系统未提供默认的gcc与cmake则还需要安装gcc、g++与cmake</strong></p><pre><code class="lang-shell">sudo dnf install -y gcc g++ cmake</code></pre><h1>解压GCC源码包并进入目录</h1><h1>下载依赖库源码</h1><pre><code class="lang-shell">./contrib/download_prerequisites</code></pre><h1>创建构建目录并在其下进行编译</h1><pre><code class="lang-shell">cd ..
mkdir gcc-build
cd gcc-build</code></pre><h1>配置编译</h1><pre><code class="lang-shell">../gcc-14.2.0/configure \
  --prefix=/usr/local/gcc-14.2 \
  --disable-multilib \
  --enable-languages=c,c++ \
  --enable-checking=release</code></pre><p><strong>gcc-14.2.0 根据实际gcc版本及解压目录替换</strong></p><h1>编译</h1><pre><code class="lang-shell">make -j$(nproc)
make install</code></pre><h1>配置环境</h1><p>在.bashrc或.bash_profile(openEular)中添加</p><pre><code class="lang-shell">LD_LIBRARY_PATH=/usr/local/gcc14/lib64/:$LD_LIBRARY_PATH
export PATH
export LD_LIBRARY_PATH</code></pre><p><strong>通过alternatives管理版本切换时，无需将bin路径导出到PATH</strong></p><h1>版本选择配置</h1><pre><code class="lang-shell">sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.2/bin/gcc 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-14.2/bin/g++ 50
sudo update-alternatives --config gcc</code></pre><ul><li>--install 安装配置信息</li><li>/usr/bin/gcc 版本切换的注册可执行文件的地址，即生成的软连接位置</li><li>gcc 注册的组名, 管理使用</li><li>/usr/local/gcc-14.2/bin/gcc 实际的可执行文件路径</li><li>50 优先级，数值越大优先级越高</li><li>--slave /usr/bin/g++ g++  /usr/local/gcc-14.2/bin/g++ ： 绑定切换，切换gcc时自动切换g++</li></ul><h1>版本切换</h1><pre><code class="lang-shell">sudo update-alternatives --config gcc

# gcc为组名
# 根据提示输入序号来选择版本</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://liar.org.cn/index.php/2025/08/20/27.html#comments</comments>
<wfw:commentRss>https://liar.org.cn/index.php/feed/category/Component/2025/08/20/27.html</wfw:commentRss>
</item>
</channel>
</rss>