プロジェクト

全般

プロフィール

Cygwin の GCC 840 ビルド » 履歴 » バージョン 3

開発 次郎, 2026/05/16 23:23

1 1 開発 次郎
h1. Cygwin の GCC 840 ビルド
2
3 2 開発 次郎
h2. 1.必要パッケージのインストール(Cygwin)
4 1 開発 次郎
5
最小構成で初期セットアップした後、GCC をビルドするため、以下のパッケージを導入をする。
6
7 2 開発 次郎
<pre><code class="text">
8 1 開発 次郎
gcc-core
9
gcc-g++
10
make
11
binutils
12
libgmp-devel
13
libmpfr-devel
14
libmpc-devel
15
flex
16
bison
17
gawk
18
wget
19
git
20 2 開発 次郎
</code></pre>
21 1 開発 次郎
22 2 開発 次郎
h2. 2. GCC 8.4.0 のソース取得
23
24
<pre><code class="bash">
25 1 開発 次郎
wget https://ftp.gnu.org/gnu/gcc/gcc-8.4.0/gcc-8.4.0.tar.xz
26
tar xf gcc-8.4.0.tar.xz
27 2 開発 次郎
</code></pre>
28
29
h2. 3. ビルド用ディレクトリを作成
30
31
<pre><code class="bash">
32 1 開発 次郎
mkdir gcc-8.4.0-build
33
cd gcc-8.4.0-build
34 2 開発 次郎
</code></pre>
35
36
h2. 4. configure の実行
37
38
<pre><code class="bash">
39 1 開発 次郎
Cygwin で long double=80bit を使うため、特別なオプションは不要。
40 2 開発 次郎
</code></pre>
41
42 1 開発 次郎
標準の configure で OK。
43
44 2 開発 次郎
<pre><code class="bash">
45 1 開発 次郎
../gcc-8.4.0/configure \
46
  --prefix=/usr/local/gcc-8.4 \
47
  --enable-languages=c,c++ \
48
  --disable-multilib
49 2 開発 次郎
</code></pre>
50
51 3 開発 次郎
願わくばこちらの方が良い。
52
53
<pre><code class="bash">
54
../gcc-8.4.0/configure \
55
  --build=x86_64-pc-cygwin \
56
  --host=x86_64-pc-cygwin \
57
  --target=x86_64-pc-cygwin \
58
  --prefix=/usr/local/gcc-8.4 \
59
  --enable-languages=c,c++ \
60
  --disable-multilib \
61
  --disable-nls \
62
  --with-system-zlib
63
</code></pre>
64
65
h3. --build/--host/--target
66
67
Cygwin では native build でも明示した方が安全。
68
特に Windows 上では configure が誤判定することがあるため、
69
明示指定はむしろ推奨。
70
71
h3. --disable-nls
72
73
国際化(gettext)を無効化。
74
GCC のビルドが軽くなり、Cygwin ではよく使われる。
75
76
h3. --with-system-zlib
77
78
Cygwin の zlib を使う。
79
GCC 内部で zlib をビルドしないので高速。
80
81
h3. --disable-multilib
82
83
Cygwin は 32bit を使わないので必須。
84
85
→ Cygwin で GCC をビルドするなら、あなたの設定は非常に良い。
86
87
88 2 開発 次郎
h2. 5. make(長時間かかる)
89
90
<pre><code class="bash">
91 1 開発 次郎
make -j$(nproc)
92 2 開発 次郎
</code></pre>
93
94 1 開発 次郎
Cygwin では fork が遅いので時間がかかるが、問題なし。
95
96 2 開発 次郎
h2. 6. インストール
97
98
<pre><code class="bash">
99 1 開発 次郎
make install
100 2 開発 次郎
</code></pre>
101
102 1 開発 次郎
インストール先:
103
104 2 開発 次郎
<pre><code class="text">
105 1 開発 次郎
/usr/local/gcc-8.4/
106 2 開発 次郎
</code></pre>
107
108
h2. 7. PATH の設定
109
110 1 開発 次郎
.bashrc に追加:
111
112 2 開発 次郎
<pre><code class="bash">
113 1 開発 次郎
export PATH=/usr/local/gcc-8.4/bin:$PATH
114 2 開発 次郎
</code></pre>
115
116 1 開発 次郎
反映:
117
118 2 開発 次郎
<pre><code class="bash">
119 1 開発 次郎
. ~/.bashrc
120 2 開発 次郎
</code></pre>
121
122
123
h2. 8. 動作確認(最重要:long double の精度)
124
125
h3. テストコード作成
126
127
<pre><code class="bash">
128 1 開発 次郎
cat > /tmp/check_ld.c << 'EOF'
129
#include <stdio.h>
130
#include <float.h>
131
132
int main(void) {
133
    printf("sizeof(long double) = %zu\n", sizeof(long double));
134
    printf("LDBL_MANT_DIG       = %d\n", LDBL_MANT_DIG);
135
    return 0;
136
}
137
EOF
138 2 開発 次郎
</code></pre>
139
140
h2. コンパイル & 実行
141
142
<pre><code class="bash">
143 1 開発 次郎
/usr/local/gcc-8.4/bin/gcc /tmp/check_ld.c -o /tmp/check_ld
144
/tmp/check_ld
145 2 開発 次郎
</code></pre>
146
147
h2. 結果(成功)
148
149
<pre><code class="text">
150 1 開発 次郎
sizeof(long double) = 16
151
LDBL_MANT_DIG       = 64
152
→ 80bit 拡張倍精度(x87 FPU)が正しく動作
153 2 開発 次郎
</code></pre>
154 1 開発 次郎
155 2 開発 次郎
h2. 9. C++ の動作確認
156
157
<pre><code class="bash">
158 1 開発 次郎
echo '#include <iostream>
159
int main(){ long double x=1.0L; std::cout<<x<<"\n"; }' > /tmp/test.cpp
160
161
/usr/local/gcc-8.4/bin/g++ /tmp/test.cpp -o /tmp/test
162
/tmp/test
163 2 開発 次郎
</code></pre>
164
165 1 開発 次郎
出力:
166
167 2 開発 次郎
<pre><code class="text">
168 1 開発 次郎
1
169 2 開発 次郎
</code></pre>
170
171 1 開発 次郎
→ libstdc++ も正常。
172
173 2 開発 次郎
h2. 10. Windows Terminal で Cygwin を快適に使用
174
175 1 開発 次郎
Windows Terminal に Cygwin プロファイルを作成
176
177
TERM=xterm-256color を設定
178
179
vi(Vim)のカラー表示が復活
180
181
日本語フォントも綺麗に表示
182
183 2 開発 次郎
h2. 11. VSCode との統合準備
184
185 1 開発 次郎
VSCode のターミナルを Cygwin bash に統一
186
187
CMake Tools / CMake 拡張をインストール
188
189
CMakePresets.json を使う構成に移行
190
191
toolchain ファイルで Windows パス を使うよう修正
192
(VSCode の cmake は Windows ネイティブのため)