Rokoisブログ

自分用技術メモ

Windows10でSwiftを使いたい

WindowsでSwiftを使いたいなと思い、調べたことの覚書

仮想環境のUbuntuでSwift環境を構築

2016年ごろにオープンソース化されたそうで、公式サイトにはXcodeUbuntuのダウンロードリンクが貼られています。 今回は2020/1/22現在の最新版Swift5.1.3をダウンロードしてUbutnu18.04での環境構築をしていきます。

最新バージョンのダウンロード

必要なものをインストール

$ sudo apt-get install clang libicu-dev

最新版をダウンロード

公式サイトからUbuntu18.04のReleasesをダウンロードします。

sudo wget https://swift.org/builds/swift-5.1.3-release/ubuntu1804/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu18.04.tar.gz

はじめてSwiftパッケージをインストールする場合は以下のコマンドを実行

gpg --keyserver hkp://pool.sks-keyservers.net \
      --recv-keys \
      '7463 A81A 4B2E EA1B 551F  FBCF D441 C977 412B 37AD' \
      '1BE1 E29A 084C B305 F397  D62A 9F59 7F4D 21A5 6D5F' \
      'A3BA FD35 56A5 9079 C068  94BD 63BC 1CFE 91D3 06C6' \
      '5E4D F843 FB06 5D7F 7E24  FBA2 EF54 30F0 71E1 B235' \
      '8513 444E 2DA3 6B7C 1659  AF4D 7638 F1FB 2B2B 08C4' \
      'A62A E125 BBBF BB96 A6E0  42EC 925C C1CC ED3D 1561' \
      '8A74 9566 2C3C D4AE 18D9  5637 FAF6 989E 1BC1 6FEA'

PGP署名の検証

$ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift

おそらく、Swift Automatic Signing Keyが変更なしであれば大丈夫

ダウンロードしたファイルを展開

tar xzf https://swift.org/builds/swift-5.1.3-release/ubuntu1804/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu18.04.tar.gz

環境変数を設定

.bashrcの一番最後の行にファイルを展開したディレクトリのPATHを記述。

$ sudo vim ~/.bashrc

変更を適用

$ source .bashrc

端末でswiftを入力してインタプリタが実行されていればインストールができている。

swift実行時のエラー

自分の場合、インストールした後、swiftを実行したら、実行はできるが次のようなエラーが出てきた

error: ld-2.27.so 0xffffffff0005c564: adding range [0x1464a-0x146ba) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message
error: ld-2.27.so 0xffffffff0005c564: adding range [0x146d0-0x146d6) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message
error: ld-2.27.so 0xffffffff0005c5c5: adding range [0x1464a-0x146ba) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message
error: ld-2.27.so 0xffffffff0005c5c5: adding range [0x146d0-0x146d6) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message

このエラーは次のコマンドを実行することで解消した。

$ sudo apt remove libc6-dbg

デバッグバージョンを削除するらしい

参照

https://swift.org/download/#using-downloads

https://askubuntu.com/questions/1167043/error-ld-2-27-so-in-swift-on-ubuntu-18-04

qiita.com