Cygwin の GCC 840 ビルド » 履歴 » バージョン 2
開発 次郎, 2026/05/16 23:19
| 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 | h2. 5. make(長時間かかる) |
||
| 52 | |||
| 53 | <pre><code class="bash"> |
||
| 54 | 1 | 開発 次郎 | make -j$(nproc) |
| 55 | 2 | 開発 次郎 | </code></pre> |
| 56 | |||
| 57 | 1 | 開発 次郎 | Cygwin では fork が遅いので時間がかかるが、問題なし。 |
| 58 | |||
| 59 | 2 | 開発 次郎 | h2. 6. インストール |
| 60 | |||
| 61 | <pre><code class="bash"> |
||
| 62 | 1 | 開発 次郎 | make install |
| 63 | 2 | 開発 次郎 | </code></pre> |
| 64 | |||
| 65 | 1 | 開発 次郎 | インストール先: |
| 66 | |||
| 67 | 2 | 開発 次郎 | <pre><code class="text"> |
| 68 | 1 | 開発 次郎 | /usr/local/gcc-8.4/ |
| 69 | 2 | 開発 次郎 | </code></pre> |
| 70 | |||
| 71 | h2. 7. PATH の設定 |
||
| 72 | |||
| 73 | 1 | 開発 次郎 | .bashrc に追加: |
| 74 | |||
| 75 | 2 | 開発 次郎 | <pre><code class="bash"> |
| 76 | 1 | 開発 次郎 | export PATH=/usr/local/gcc-8.4/bin:$PATH |
| 77 | 2 | 開発 次郎 | </code></pre> |
| 78 | |||
| 79 | 1 | 開発 次郎 | 反映: |
| 80 | |||
| 81 | 2 | 開発 次郎 | <pre><code class="bash"> |
| 82 | 1 | 開発 次郎 | . ~/.bashrc |
| 83 | 2 | 開発 次郎 | </code></pre> |
| 84 | |||
| 85 | |||
| 86 | h2. 8. 動作確認(最重要:long double の精度) |
||
| 87 | |||
| 88 | h3. テストコード作成 |
||
| 89 | |||
| 90 | <pre><code class="bash"> |
||
| 91 | 1 | 開発 次郎 | cat > /tmp/check_ld.c << 'EOF' |
| 92 | #include <stdio.h> |
||
| 93 | #include <float.h> |
||
| 94 | |||
| 95 | int main(void) { |
||
| 96 | printf("sizeof(long double) = %zu\n", sizeof(long double)); |
||
| 97 | printf("LDBL_MANT_DIG = %d\n", LDBL_MANT_DIG); |
||
| 98 | return 0; |
||
| 99 | } |
||
| 100 | EOF |
||
| 101 | 2 | 開発 次郎 | </code></pre> |
| 102 | |||
| 103 | h2. コンパイル & 実行 |
||
| 104 | |||
| 105 | <pre><code class="bash"> |
||
| 106 | 1 | 開発 次郎 | /usr/local/gcc-8.4/bin/gcc /tmp/check_ld.c -o /tmp/check_ld |
| 107 | /tmp/check_ld |
||
| 108 | 2 | 開発 次郎 | </code></pre> |
| 109 | |||
| 110 | h2. 結果(成功) |
||
| 111 | |||
| 112 | <pre><code class="text"> |
||
| 113 | 1 | 開発 次郎 | sizeof(long double) = 16 |
| 114 | LDBL_MANT_DIG = 64 |
||
| 115 | → 80bit 拡張倍精度(x87 FPU)が正しく動作 |
||
| 116 | 2 | 開発 次郎 | </code></pre> |
| 117 | 1 | 開発 次郎 | |
| 118 | 2 | 開発 次郎 | h2. 9. C++ の動作確認 |
| 119 | |||
| 120 | <pre><code class="bash"> |
||
| 121 | 1 | 開発 次郎 | echo '#include <iostream> |
| 122 | int main(){ long double x=1.0L; std::cout<<x<<"\n"; }' > /tmp/test.cpp |
||
| 123 | |||
| 124 | /usr/local/gcc-8.4/bin/g++ /tmp/test.cpp -o /tmp/test |
||
| 125 | /tmp/test |
||
| 126 | 2 | 開発 次郎 | </code></pre> |
| 127 | |||
| 128 | 1 | 開発 次郎 | 出力: |
| 129 | |||
| 130 | 2 | 開発 次郎 | <pre><code class="text"> |
| 131 | 1 | 開発 次郎 | 1 |
| 132 | 2 | 開発 次郎 | </code></pre> |
| 133 | |||
| 134 | 1 | 開発 次郎 | → libstdc++ も正常。 |
| 135 | |||
| 136 | 2 | 開発 次郎 | h2. 10. Windows Terminal で Cygwin を快適に使用 |
| 137 | |||
| 138 | 1 | 開発 次郎 | Windows Terminal に Cygwin プロファイルを作成 |
| 139 | |||
| 140 | TERM=xterm-256color を設定 |
||
| 141 | |||
| 142 | vi(Vim)のカラー表示が復活 |
||
| 143 | |||
| 144 | 日本語フォントも綺麗に表示 |
||
| 145 | |||
| 146 | 2 | 開発 次郎 | h2. 11. VSCode との統合準備 |
| 147 | |||
| 148 | 1 | 開発 次郎 | VSCode のターミナルを Cygwin bash に統一 |
| 149 | |||
| 150 | CMake Tools / CMake 拡張をインストール |
||
| 151 | |||
| 152 | CMakePresets.json を使う構成に移行 |
||
| 153 | |||
| 154 | toolchain ファイルで Windows パス を使うよう修正 |
||
| 155 | (VSCode の cmake は Windows ネイティブのため) |