LoginSignup
6
3

More than 3 years have passed since last update.

ArchWSL と yay 及び Mingw-w64 を用いて MSYS2 風 Windows アプリケーション開発環境を構築する

Last updated at Posted at 2019-11-09

本記事では「 base-devel 及び mingw-w64-x86_64-toolchain 導入済みの MSYS2 」に類似のクロス開発環境の構築をもきゅ目標としています。


 無 保 証 で す

当方執筆の技術情報に関するライセンス、免責事項、禁止事項

3行でまとめられず申し訳ない、つきましては今少し時間と予算をいただければ……

ArchWSL
https://github.com/yuk7/ArchWSL/blob/master/README.ja.md

yay
https://github.com/Jguer/yay

Mingw-w64 - GCC for Windows 64 & 32 bits[mingw-w64]
http://mingw-w64.org/doku.php

MinGW パッケージガイドライン - ArchWiki
https://wiki.archlinux.org/index.php/MinGW_package_guidelines
https://wiki.archlinux.jp/index.php/MinGW_%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3

$HOME/.bashrc に書き加えて使用して下さい
.bashrcに書き加えて下さい
# cross-compiling environment
deactivate-mingw64 () {
    unset CC
    unset CFLAGS
    unset CXX
    unset CXXFLAGS
    unset CPP
    unset CPPFLAGS
    unset LDFLAGS
    unset PKG_CONFIG
    unset PKG_CONFIG_PATH
    export PATH=$(echo $PATH | sed 's/\/usr\/x86_64-w64-mingw32\/bin://')
    export PS1=$(echo $PS1 | sed -e 's/(MinGW64) //' -e 's/ $//')" "
}
activate-mingw64 () {
    export CC=/usr/sbin/x86_64-w64-mingw32-gcc
    export CFLAGS="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -static"
    export CXX=/usr/sbin/x86_64-w64-mingw32-g++
    export CXXFLAGS="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -static"
    export CPP=/usr/sbin/x86_64-w64-mingw32-cpp
    export CPPFLAGS="-D_FORTIFY_SOURCE=2 -I/usr/x86_64-w64-mingw32/include"
    export LDFLAGS="-Wl,-O1,--sort-common,--as-needed -L/usr/x86_64-w64-mingw32/lib"
    export PKG_CONFIG=/usr/sbin/x86_64-w64-mingw32-pkg-config
    export PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/lib/pkgconfig
    export PATH="/usr/x86_64-w64-mingw32/bin:$PATH"
    export PS1='(MinGW64) '"$PS1"
    echo
    echo "SYSTEM INFORMATION:"
    uname -a
    echo
    echo "VERSION OF C COMPILER:"
    $CC --version
    echo
    echo "VERSION OF C++ COMPILER:"
    $CXX --version
    echo
}

参考とした文献

参考とした文献

 
冒険航空会社モンタナ | NHKアニメワールド
https://www6.nhk.or.jp/anime/program/detail.html?i=montana
 
ニトロ博士 (にとろはかせ)とは【ピクシブ百科事典】
https://dic.pixiv.net/a/%E3%83%8B%E3%83%88%E3%83%AD%E5%8D%9A%E5%A3%AB
 
HTMLタグ 文字の色を指定する - Webページ作りのお勉強 HTMLタグでHP作り
http://masaboo.cside.com/new_html1/ht_06.htm
 
HTML font color Attribute - W3Schools Online Web Tutorials
https://www.w3schools.com/tags/att_font_color.asp

概要

MSYS2 はその基盤として CygwinPOSIX 互換機能の提供に1pacman をパッケージ管理機能の提供に2用いていますが、そこを ArchWSLyay で差し替えてみるのが本記事の趣旨です。

システム構成図.jpg

なお、WSL1(及び 2)は POSIX 互換機能と呼ぶよりも Linux 互換機能と呼ぶ方が自然かもしれません。もしかすると Android-x86 も行けるかな?

ところで、MinGW-w64 公式サイトのダウンロードページの記述を見ると、パッケージの充実度は一位が MSYS2 で二位が Arch Linux(の AUR)のようでした(many > 305)。

Mingw-w64.jpg


2019 年 11 月現在 AUR の "Mingw-w64" で始まるパッケージを簡単に数取りしたところ、614 を数えました。順調に増えているようです。

AUR (en) - Search Criteria: mingw-w64
https://aur.archlinux.org/packages/?K=mingw-w64

yay -Ss mingw-w64 | grep "aur/" | wc -l
614

MAN/INFOPAGE

MSYS2 の場合、https://github.com/msys2/MINGW-packages の mingw-w64-<ソフトウェア名> であるフォルダを数えたところ 1470 ありました。

Search results for "mingw-w64" - Base Packages - MSYS2 Packages
https://packages.msys2.org/search?t=pkg&q=mingw-w64

git clone https://github.com/msys2/MINGW-packages.git
cd MINGW-packages
ls -l | grep mingw-w64 | wc -l
1470

MAN/INFOPAGE

参考とした文献

参考とした文献

 
シェル (shell)とは|「分かりそう」で「分からない」でも「分かった」気になれるIT用語辞典
https://wa3.i-3-i.info/word11219.html
 
完全なLinuxがWindows 10上で稼働する? 「WSL 2」とは:Windows 10 The Latest - @IT
https://www.atmarkit.co.jp/ait/articles/1906/14/news019.html
 
「WSL 2」は「Windows 10 Home」でも利用可能 ~MicrosoftがFAQを掲載 - 窓の杜
https://forest.watch.impress.co.jp/docs/news/1184353.html
 
Announcing WSL 2 | Windows Command Line
https://devblogs.microsoft.com/commandline/announcing-wsl-2/
 
Windows Subsystem for Linux の詳細 | Microsoft Docs
https://docs.microsoft.com/ja-jp/windows/wsl/about
https://docs.microsoft.com/en-us/windows/wsl/about
 
WSL 1 と WSL 2 の間での UX の変更 | Microsoft Docs
https://docs.microsoft.com/ja-jp/windows/wsl/wsl2-about
https://docs.microsoft.com/en-us/windows/wsl/wsl2-about

POSIX 互換レイヤーを噛ませない場合

MinGW-W64 の Online Installer による環境構築

MinGW-W64 の使い方

GNU Autotools 系を導入する場合、GnuWin32 等からダウンロードする、MSYS2 の MinGW64 サブシステムから拝借する等します。

環境の立ち上げは、mingw-w64.bat の実行によって行います。インストール時の選択次第ですが、C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw-w64.bat 等として存在します。

CMake は cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE=Release .. 等で実行、make は MinGW-W64 Online Installer により導入され、 mingw32-make コマンドとして存在します。必要なら make.exe としてシンボリックリンクを作成しても良いかもしれません 3 4 5 6

Ninja を使う場合は mingw-w64.bat を編集し ninja.exe が存在するフォルダをパスに追加するか、もしくは mingw-w64.bat で開いた端末から where mingw32-make を実行、 表示された mingw32-make.exe が存在するのと同じフォルダに ninja.exe をコピー&ペーストしておきます。

利点と課題

このようにして構築した環境はシステム構成が単純化されることでエラー発生時の問題の切り分けが容易くなることが期待出来る反面、UNIX シェル含まないため configure スクリプトの実行に支障があります。もしもシェルスクリプトを PowerShell が理解出来る、ないし configure スクリプトを PowerShell スクリプトに変換出来るならば簡単で良いのですが。

システム構成図2.jpg

その後アヒルさんに尋ねたところ、Autotools to CMake なコンバータ7 8 が引っ掛かりました。

参考とした文献

参考とした文献

 
MinGW Makefiles — CMake 3.16.0-rc3 Documentation
https://cmake.org/cmake/help/latest/generator/MinGW%20Makefiles.html
 
CMAKE_BUILD_TYPE — CMake 3.16.0-rc3 Documentation
https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
 
c++ - The equivalent of ./configure in Windows? - Stack Overflow
https://stackoverflow.com/questions/4179800/the-equivalent-of-configure-in-windows
 
Windows 10 Homeに導入したMSYS2(Minimal SYStem2)にGitを - ts0818のブログ
https://ts0818.hatenablog.com/entry/2017/05/30/163740
 
linux - シェル、ターミナル、コマンドプロンプトの違いを教えてください - スタック・オーバーフロー
https://ja.stackoverflow.com/questions/24549/%E3%82%B7%E3%82%A7%E3%83%AB-%E3%82%BF%E3%83%BC%E3%83%9F%E3%83%8A%E3%83%AB-%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83%97%E3%83%AD%E3%83%B3%E3%83%97%E3%83%88%E3%81%AE%E9%81%95%E3%81%84%E3%82%92%E6%95%99%E3%81%88%E3%81%A6%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84
 
SEHとかSJLJとか | Scenery and Fish
http://sceneryandfish.withnotes.net/?p=1689
 
c++ - What is difference between sjlj vs dwarf vs seh? - Stack Overflow
https://stackoverflow.com/questions/15670169/what-is-difference-between-sjlj-vs-dwarf-vs-seh
 
windows - mingw-w64 threads: posix vs win32 - Stack Overflow
https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32
 
c++ - Whats the difference between thread_posixs and thread_win32 in gcc port of windows? - Stack Overflow
https://stackoverflow.com/questions/13212342/whats-the-difference-between-thread-posixs-and-thread-win32-in-gcc-port-of-windo
 
MinGWのmakeコマンドについて - (仮)
https://blog.goo.ne.jp/presscuby/e/374b4837cf74d0ee785082259aa0c772
 
MinGWのmingw32-makeを使って、PythonのC言語拡張をビルドする - Symfoware
https://symfoware.blog.fc2.com/blog-entry-821.html
 
ダウンロードファイルが真正なものであるかを確認:仕事で使える魔法のLAMP(10) - @IT
https://www.atmarkit.co.jp/ait/articles/1106/17/news138.html
 
keyword=WSL - Explore Microsoft open source projects, releases and information - opensource.microsoft.com
https://opensource.microsoft.com/?sort=Awesomeness&keyword=WSL
 
Symbolic Links - Win32 apps | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/fileio/symbolic-links
 
symlink - Creating hard and soft links using PowerShell - Stack Overflow
https://stackoverflow.com/questions/894430/creating-hard-and-soft-links-using-powershell
 
New-Item - PowerShell Documentation | Microsoft Docs
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-6

Mingw-w64 以外のアプローチ

Linux 上で exe ファイルを生成する場合、Mingw-w64 以外では .NET を用いるやり方が考えられます。後者を扱う場合の選択肢として Mono や .NET Core があります。

Home | Mono
https://www.mono-project.com/

.NET | Free. Cross-platform. Open Source.
https://dotnet.microsoft.com/

参考とした文献

参考とした文献

 
Building Win32 GUI Applications with MinGW
https://www.transmissionzero.co.uk/computing/win32-apps-with-mingw/
 
.NET Coreでコンソールアプリを配置する - Build Insider
https://www.buildinsider.net/language/dotnetcore/04
 
.NETアプリをLinux対応にするMono - IBM developerWorks 日本語版
https://www.ibm.com/developerworks/jp/linux/library/l-mono/index.html
 
.NET Core – How to publish a self-contained application (.exe) – Luís Henrique Demetrio
https://blogs.msdn.microsoft.com/luisdem/2016/10/11/net-core-how-to-publish-a-self-contained-application-exe/
 
Debugging .NET Core From VS2017 on Windows Subsystem for Linux – DOTNET CATCH – Blogging .NET, C# and DevOps topics.
https://www.dotnetcatch.com/2017/04/23/debugging-net-core-from-vs2017-on-windows-subsystem-for-linux/
 
Running .NET Core on Windows Subsystem for Linux - Leow Kah Man - Tech Blog
https://www.leowkahman.com/2017/04/23/running-dotnet-core-on-windows-subsystem-for-linux/
 
compilation - How to compile a .NET application to native code? - Stack Overflow
https://stackoverflow.com/questions/45702/how-to-compile-a-net-application-to-native-code
 
MinGW-w64 - for 32 and 64 bit Windows - Browse /mingw-w64 at SourceForge.net
https://sourceforge.net/projects/mingw-w64/files/mingw-w64/
 
Windows API - Wikipedia
https://ja.wikipedia.org/wiki/Windows_API
 
.NET Core - Wikipedia
https://ja.wikipedia.org/wiki/.NET_Core

ArchWSL の導入

公式サイト
https://git.io/archwsl

日本語README
https://github.com/yuk7/ArchWSL/blob/master/README.ja.md

1. Known issues を読む

Known issues · yuk7/ArchWSL Wiki · GitHub
https://github.com/yuk7/ArchWSL/wiki/Known-issues

Known issues · yuk7/wsldl Wiki · GitHub
https://github.com/yuk7/wsldl/wiki/Known-issues

2. GitHub のリリースページから ArchWSL-AppX_<バージョン>_x64.appx 及び ArchWSL-AppX_<バージョン>_x64.cer をダウンロードする

2019-11-03 (1).png

3. ArchWSL-AppX_<バージョン>_x64.cer をインポートする

  • ArchWSL-AppX_<バージョン>_x64.cer を右クリックし、「証明書のインストール(I)」

  • 「開いているファイル - セキュリティの警告」ダイアログで[開く(O)]

  • 「証明書のインポートウィザード」が起動するので以下の手順で証明書をインポート

    • 保存場所 => ローカル コンピュータ(L)=> [次へ(N)]
    • 証明書ストア => 証明書をすべて次のストアに配置する(P)=> [参照(R)]
    • 証明書ストアの選択 => 信頼されたルート証明機関 => [OK]
    • 証明書ストア => [次へ(N)]=> [完了(F)]
    • 正しくインポートされました => [OK]

スクリーンショット

 
2019-10-31 (11).png
2019-10-31 (12).png
2019-10-31 (13).png
2019-10-31 (14).png
2019-10-31 (16).png
2019-10-31 (17).png

出典:

4. ArchWSL-AppX_<バージョン>_x64.appx をインストールする

ArchWSL-AppX_<バージョン>_x64.appx をダブルクリックし、App Installer でインストールする。

2019-11-06 (3).png

5. ArchWSL を立ち上げ、基本的な環境の構築作業を行う

ArchWSL_初回起動時
passwd # ルートパスワードを設定する
EDITOR=nano visudo # 用途に応じたアンコメントを行い sudo を設定する
useradd -m -G wheel -s /bin/bash hogefuga # ユーザーを追加する(hogefuga は使いたいユーザー名に置き換える)
passwd hogefuga # ユーザー hogefuga に新規パスワードを付与する
exit

MAN/INFOPAGE

コマンドプロンプトから
@REM hogefuga を通常使うユーザーに指定する。
Arch.exe config --default-user hogefuga
exit

MAN/INFOPAGE

 
Arch.exe
https://github.com/yuk7/ArchWSL/wiki/How-to-Use(for-Installed-Instance)
 
REM

REM /?
バッチ ファイルまたは CONFIG.SYS にコメント (注釈) を記録します。

REM [コメント]

EXIT

EXIT /?
CMD.EXE プログラム (コマンド インタープリター) またはバッチ スクリプトを終了
します。
EXIT [/B] [終了コード]
/B CMD.EXE ではなく、現在のバッチ スクリプトを終了するように指定
します。バッチ スクリプトの外から実行された場合、CMD.EXE を終
了させます。
終了コード 数値を指定します。/B が指定されている場合、ERRORLEVEL にその
数値を設定します。CMD.EXE 終了をする場合、プロセス終了コードに
その数値を設定します。


ArchWSL_二回目起動時
# pacman を使うための準備を行う
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman -Syuu

MAN/INFOPAGE

 
sudo
https://linuxjm.osdn.jp/html/sudo/man8/sudo.8.html
alias 須藤=sudo とすることで、須藤sudo 出来るようになります。
 
pacman-key
https://www.archlinux.org/pacman/pacman-key.8.html
 
pacman
https://www.archlinux.org/pacman/pacman.8.html

ArchWSL における systemd や systemctl

systemd/systemctl - Known issues · yuk7/ArchWSL Wiki · GitHub
https://github.com/yuk7/ArchWSL/wiki/Known-issues#systemdsystemctl

備考

  • この節の内容は、ほぼ How To Setup そのままです。

  • wheel グループは sudo の許可・不許可に関わるグループ名です。

  • 自分が躓いた部分:useradd ではユーザー名に大文字が使えません(Windows や MSYS2 だと大文字のユーザー名も O.K.)。初歩的なことで暫く悩んでしまったよワトソン君。

関連する文献

関連する文献

 
[Linux] なぜ sudo する権限のあるグループが「 wheel 」という名前なのか « Codaholic
http://codaholic.org/?p=1757

初期化

ArchWSL のインストール直後の状態への初期化はコマンドプロンプトや PowerShell から、Arch.exe clean です。これを実行してしまうとバックアップを取っていないデータは失われてしまい元に戻せません。よって事前に Arch.exe backup しておくと良いでしょう。詳細は公式サイト及び Arch.exe help で確認して下さい。

image.png

Arch.exe clean 実行後に再度 Arch.exe を実行することで ArchWSL 環境が再構築されます。

参考とした文献

参考とした文献

 
Home · yuk7/wsldl Wiki · GitHub
https://github.com/yuk7/wsldl/wiki
 
How to Setup · yuk7/ArchWSL Wiki · GitHub
https://github.com/yuk7/ArchWSL/wiki/How-to-Setup
 
How to Use(for Installed Instance) · yuk7/ArchWSL Wiki · GitHub
https://github.com/yuk7/ArchWSL/wiki/How-to-Use(for-Installed-Instance)
 
Known issues · yuk7/ArchWSL Wiki · GitHub
https://github.com/yuk7/ArchWSL/wiki/Known-issues
 
Known issues · yuk7/ArchWSL Wiki · GitHub
https://github.com/yuk7/wsldl/wiki/Known-issues
 
ArchWSL/README.ja.md at master · yuk7/ArchWSL · GitHub
https://github.com/yuk7/ArchWSL/blob/master/README.ja.md
 
wsldl/README.ja.md at master · yuk7/wsldl · GitHub
https://github.com/yuk7/wsldl/blob/master/README.ja.md
 
pacman-key(8) Manual Page - Pacman Home Page
https://www.archlinux.org/pacman/pacman-key.8.html
 
[SOLVED] What does "pacman -Syuu" and "pacman -Syy" do? / Newbie Corner / Arch Linux Forums
https://bbs.archlinux.org/viewtopic.php?id=141029
 
コメントの記述(REM) | コマンドプロンプトの使い方 - ApacheとWordPressの解説ならAdminWeb
https://www.adminweb.jp/command/bat/index4.html
 
Linuxのアカウント名の文字や文字数の制限について - QA@IT
https://qa.atmarkit.co.jp/q/947
 
REM /?
REM /?
バッチ ファイルまたは CONFIG.SYS にコメント (注釈) を記録します。

REM [コメント]

おまけ

MSYS2のようなCドライブへのアクセスの実現
sudo ln -s /mnt/c /c

MAN/INFOPAGE

FHS に叱られる……(´・ω・`)

/etc/sudoers の編集とパスワードなしの sudo の許可

yay による基本的なパッケージ群のビルド&インストール作業が終わるまで、sudo でパスワードを要求しないよう変更しておきます。作業終了後に元に戻すのを忘れずに。

visudoを起動します。
su -l -c "EDITOR=nano visudo"

MAN/INFOPAGE

こちらをアンコメントします。
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
通常アンコメントするのはこちらです。
## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL) ALL

関連する文献

関連する文献

 
Visudo Manual - Sudo Main Page
https://www.sudo.ws/man/1.8.28/visudo.man.html

基本的な開発パッケージ群の導入

base-devel相当のパッケージ群をインストールします。
sudo pacman -Syu
sudo pacman -S autoconf automake binutils bison file findutils flex gawk gcc gettext grep groff gzip libtool m4 make pacman patch pkgconf sed sudo texinfo util-linux which

MAN/INFOPAGE

sudo pacman -S base-devel で一括インストールしても良いのですが、その場合バージョン固定された fakeroot(fakeroot-tcp)をアップデートしないように気を付けて下さい。

sudo pacman -S base-devel
$ sudo pacman -S base-devel
:: fakeroot is in IgnorePkg/IgnoreGroup. Install anyway? [Y/n] n
:: There are 24 members in group base-devel:
:: Repository core
   1) autoconf  2) automake  3) binutils  4) bison  5) file  6) findutils  7) flex  8) gawk  9) gcc  10) gettext
   11) grep  12) groff  13) gzip  14) libtool  15) m4  16) make  17) pacman  18) patch  19) pkgconf  20) sed  21) sudo
   22) texinfo  23) util-linux  24) which

Enter a selection (default=all):
warning: file-5.37-3 is up to date -- reinstalling
warning: findutils-4.7.0-1 is up to date -- reinstalling
warning: gawk-5.0.1-1 is up to date -- reinstalling
warning: gettext-0.20.1-2 is up to date -- reinstalling
warning: grep-3.3-2 is up to date -- reinstalling
warning: groff-1.22.4-1 is up to date -- reinstalling
warning: gzip-1.10-2 is up to date -- reinstalling
warning: pacman-5.2.0-2 is up to date -- reinstalling
warning: sed-4.7-2 is up to date -- reinstalling
warning: sudo-1.8.29-1 is up to date -- reinstalling
warning: util-linux-2.34-3 is up to date -- reinstalling
warning: which-2.21-4 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (28) gc-8.0.4-2  guile-2.2.6-1  libatomic_ops-7.6.10-1  libmpc-1.1.0-1  autoconf-2.69-5  automake-1.16.1-1
              binutils-2.33.1-1  bison-3.4.2-1  file-5.37-3  findutils-4.7.0-1  flex-2.6.4-2  gawk-5.0.1-1  gcc-9.2.0-3
              gettext-0.20.1-2  grep-3.3-2  groff-1.22.4-1  gzip-1.10-2  libtool-2.4.6+42+gb88cebd5-6  m4-1.4.18-2
              make-4.2.1-3  pacman-5.2.0-2  patch-2.7.6-7  pkgconf-1.6.3-2  sed-4.7-2  sudo-1.8.29-1  texinfo-6.7-1
              util-linux-2.34-3  which-2.21-4

Total Download Size:    57.13 MiB
Total Installed Size:  282.46 MiB
Net Upgrade Size:      234.00 MiB

:: Proceed with installation? [Y/n]

nano には “nano-syntax-highlighting” が便利です。

必要に応じてインストールします。
sudo pacman -S nano-syntax-highlighting

MAN/INFOPAGE

nano-syntax-highlighting_の使い方
# nano-syntax-highlighting-git の導入後メッセージより引用
==> IMPORTANT!!!
==> To prevent overwriting your existing configuration, nanorc
==> was installed to /usr/share/nano-syntax-highlighting/nanorc.sample
==>
==> To install you should add the languages you want to your nano configuration file, system-wide or user-specific
==> system-wide: $ echo "include /usr/share/nano-syntax-highlighting/*.nanorc" >> /etc/nanorc
==> user-specific: $ echo "include /usr/share/nano-syntax-highlighting/*.nanorc" >> ~/.nanorc

ArchWSL にプリインストールされている fakeroot-tcp について

Known Issues の fakeroot セクションより引用

fakeroot
fakeroot is using SYSV IPC by default. but WSL does not support it now.

You can use fakeroot-tcp package instead.

Download fakeroot-tcp-1.23-1-x86_64.pkg.tar.xz and run pacman -U fakeroot-tcp-1.23-1-x86_64.pkg.tar.xz to install.

プリインストール版 fakeroot-tcp の情報
$ pacman -Qi fakeroot-tcp
Name            : fakeroot-tcp
Version         : 1.23-1
Description     : Tool for simulating superuser privileges,with tcp ipc
Architecture    : x86_64
URL             : http://packages.debian.org/fakeroot
Licenses        : GPL
Groups          : None
Provides        : fakeroot=1.23-1
Depends On      : glibc  filesystem  sed  util-linux  sh
Optional Deps   : None
Required By     : None
Optional For    : None
Conflicts With  : fakeroot
Replaces        : None
Installed Size  : 234.00 KiB
Packager        : Unknown Packager
Build Date      : Tue 21 Aug 2018 12:06:49 AM JST
Install Date    : Fri 11 Oct 2019 01:21:57 AM JST
Install Reason  : Explicitly installed
Install Script  : Yes
Validated By    : None

※ fakeroot が正常動作しない場合、yay が動作不良を起こすものと思われます。

関連する文献

関連する文献

yay の導入

yayをダウンロード&ビルド&インストールします。
sudo pacman -Syu
sudo pacman -S git go
cd
mkdir Downloads
cd Downloads
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

MAN/INFOPAGE

yay は一般ユーザーとして実行します。root として実行しようとすると Please avoid running yay as root/sudo. と警告を発します。また、yay では AUR のリポジトリも Arch 標準のリポジトリも両方共に扱えます。

また、プレコンパイルドバージョンがあるので、そちらの PKGBUILD をローカルに落として buildpkg -si makepkg -si しても良いかもしれません9

出典

関連する文献

関連する文献

 
what is the abbreviation of GIT? - Stack Overflow
https://stackoverflow.com/questions/43959748/what-is-the-abbreviation-of-git
 
Linus Torvalds氏によるGitの内部構造の解説 - Qiita
https://qiita.com/hogemax/items/b09abc522e0ec05da4fe
 
Git - Documentation
https://git-scm.com/doc
 
Documentation - The Go Programming Language
https://golang.org/doc/
 
Renée French - Wikipedia
https://en.wikipedia.org/wiki/Ren%C3%A9e_French

French drew both the mascot of the Plan 9 from Bell Labs operating system ("Glenda", aka "the Plan 9 Bunny"), and the gopher mascot for the Go programming language.

基本的な Mingw-w64 開発パッケージ群の導入

MSYS2のmingw-w64-x86_64-toolchain相当のパッケージ群をインストールします。
yay
yay -S mingw-w64-crt-bin mingw-w64-binutils-bin mingw-w64-winpthreads-bin mingw-w64-headers-bin mingw-w64-gcc-bin mingw-w64-pkg-config mingw-w64-pdcurses-win32a mingw-w64-gdb mingw-w64-tools mingw-w64-libtool mingw-w64-configure mingw-w64-gc mingw-w64-flex-wrapper mingw-w64-gettext

MAN/INFOPAGE

 
yay
https://github.com/Jguer/yay/blob/master/doc/yay.8
https://github.com/Jguer/yay/blob/master/README.md
※ yay で yay を再導入するなら多分 yay && yay -S yay。yay だらけ。

ビルドエラーについて

現在は修正されています。

2019年11月11日15時現在、mingw-w64-tools が sha256sum エラーを起こします。MinGW-W64 の公式がリビジョンを上げずに同じ名前でファイルを更新してしまったっぽい?(ないとは思うけどクラッキングだったら嫌だなぁ)

一応の回避策として、mingw-w64-tools の構築依存を全部入れた上で AUR から PKGBUILD を落として sha256sum を書き換えることでなんとかなりそうです。

mingw-w64-tools のビルドエラー
$ git clone https://aur.archlinux.org/mingw-w64-tools.git

$ cd mingw-w64-tools

$ makepkg -si
==> Making package: mingw-w64-tools 7.0.0-1 (Mon 11 Nov 2019 02:30:39 PM JST)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Downloading mingw-w64-v7.0.0.tar.bz2...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18014  100 18014    0     0  13284      0  0:00:01  0:00:01 --:--:-- 13274
100 18001  100 18001    0     0  10676      0  0:00:01  0:00:01 --:--:-- 10676
100 18076  100 18076    0     0   9533      0  0:00:01  0:00:01 --:--:--  9533
100   389  100   389    0     0    126      0  0:00:03  0:00:03 --:--:--   428
100 8858k  100 8858k    0     0  1187k      0  0:00:07  0:00:07 --:--:-- 2070k
  -> Downloading mingw-w64-v7.0.0.tar.bz2.sig...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 18021  100 18021    0     0  13672      0  0:00:01  0:00:01 --:--:-- 13683
100 18008  100 18008    0     0  12069      0  0:00:01  0:00:01 --:--:-- 12069
100 18084  100 18084    0     0  10893      0  0:00:01  0:00:01 --:--:--     0
100   397  100   397    0     0    140      0  0:00:02  0:00:02 --:--:--  1464
100   148  100   148    0     0     41      0  0:00:03  0:00:03 --:--:--  4933
==> Validating source files with sha256sums...
    mingw-w64-v7.0.0.tar.bz2 ... FAILED
    mingw-w64-v7.0.0.tar.bz2.sig ... Skipped
==> ERROR: One or more files did not pass the validity check!

$ sha1sum mingw-w64-v7.0.0.tar.bz2
25940043c4541e3e59608dead9b6f75b5596d606  mingw-w64-v7.0.0.tar.bz2

$ md5sum mingw-w64-v7.0.0.tar.bz2
7cd9b09be0b2c658ce200c4c43b59b27  mingw-w64-v7.0.0.tar.bz2

$ sha256sum mingw-w64-v7.0.0.tar.bz2
aa20dfff3596f08a7f427aab74315a6cb80c2b086b4a107ed35af02f9496b628  mingw-w64-v7.0.0.tar.bz2

$ cat PKGBUILD | grep sha256sums
sha256sums=('f5c9a04e1a6c02c9ef2ec19b3906ec4613606d1b5450d34bbd3c4d94ac696b3b'

sha256sum の他に PKGBUILD 中の v6.0.0 も v7.0.0 に書き換えるとビルドが通りました。

備考

  • mingw-w64-libiconv の選択肢について:mingw-w64-win-iconv は現在メンテナ不在のため、mingw-w64-libiconv を選択するのが良さそうです。
    $ yay -Ss mingw-w64-libiconv; yay -Ss mingw-w64-win-iconv
    $ yay -Ss mingw-w64-libiconv
    aur/mingw-w64-libiconv 1.16-1 (+32 0.22%)
        Provides GNU libiconv.so and libcharset.so (mingw-w64)
    $ yay -Ss mingw-w64-win-iconv
    aur/mingw-w64-win-iconv 0.0.8-1 (+3 0.00%) (Orphaned)
        Iconv implementation using Win32 API (mingw-w64)
    

    • mingw-w64-x86_64-toolchain に所属するパッケージのリスト
      https://packages.msys2.org/group/mingw-w64-x86_64-toolchain

    • -bin で終わっているものはコンパイル済みバイナリのパッケージであり、これらを選択することで yay の実行時間の短縮が期待できます。一方でソースからビルドする場合はビルドオプションを柔軟に指定出来るものもありますし、どちらが優れているかは求めるものによると思います。

    AUR に見つからなかったパッケージ(2019年11月時点)

    mingw-w64-x86_64-libmangle-git
    mingw-w64-x86_64-winstorecompat-git

    リストに +α したパッケージ

    base-devel インストール時に導入されるパッケージに対応する Mingw-w64 版パッケージ

    mingw-w64-libtool
    mingw-w64-configure
    mingw-w64-gc
    mingw-w64-flex-wrapper
    mingw-w64-gettext

    mingw-w64-libmpc は wine 関連の大量の依存関係を引き連れるのでリストへの採用を見送りました。

    clang

    mingw-w64-clang-git
    MinGW clang wrapper (wclang)

    yay
    yay -S mingw-w64-clang-git
    

    MAN/INFOPAGE

    $HOME/.bashrc 用環境設定関数

    activate-mingw64 で MinGW64 環境の立ち上げ、deactivate-mingw64 で MinGW64 環境の終了です。主に configure や cmake が使えないソフトウェア用。

    MinGW64 環境を立ち上げた状態から yay を実行しないで下さい。ビルドの失敗や、生成されるバイナリの変質が起こるかもしれません。

    .bashrcに書き加えて下さい
    # cross-compiling environment
    deactivate-mingw64 () {
        unset CC
        unset CFLAGS
        unset CXX
        unset CXXFLAGS
        unset CPP
        unset CPPFLAGS
        unset LDFLAGS
        unset PKG_CONFIG
        unset PKG_CONFIG_PATH
        export PATH=$(echo $PATH | sed 's/\/usr\/x86_64-w64-mingw32\/bin://')
        export PS1=$(echo $PS1 | sed -e 's/(MinGW64) //' -e 's/ $//')" "
    }
    activate-mingw64 () {
        export CC=/usr/sbin/x86_64-w64-mingw32-gcc
        export CFLAGS="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -static"
        export CXX=/usr/sbin/x86_64-w64-mingw32-g++
        export CXXFLAGS="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -static"
        export CPP=/usr/sbin/x86_64-w64-mingw32-cpp
        export CPPFLAGS="-D_FORTIFY_SOURCE=2 -I/usr/x86_64-w64-mingw32/include"
        export LDFLAGS="-Wl,-O1,--sort-common,--as-needed -L/usr/x86_64-w64-mingw32/lib"
        export PKG_CONFIG=/usr/sbin/x86_64-w64-mingw32-pkg-config
        export PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/lib/pkgconfig
        export PATH="/usr/x86_64-w64-mingw32/bin:$PATH"
        export PS1='(MinGW64) '"$PS1"
        echo
        echo "SYSTEM INFORMATION:"
        uname -a
        echo
        echo "VERSION OF C COMPILER:"
        $CC --version
        echo
        echo "VERSION OF C++ COMPILER:"
        $CXX --version
        echo
    }
    

    MAN/INFOPAGE

     
    (){}
    https://linuxjm.osdn.jp/html/GNU_bash/man1/bash.1.html
    :(){ :|:& };: 其は侵すべからざる神聖十三文字。嗚呼不遜なる者共、TUX怒りを畏れよ。彼の祝詞濫りに唱えることなかれ。私は何を言っているんだ。
     
    unset,export,echo
    https://linuxjm.osdn.jp/html/GNU_bash/man1/builtins.1.html
     
    sed
    https://linuxjm.osdn.jp/html/GNU_sed/man1/sed.1.html
    https://www.gnu.org/software/sed/manual/sed.html

    参考とした文献

     
    MinGW package guidelines - ArchWiki
    https://wiki.archlinux.org/index.php/MinGW_package_guidelines
     
    MinGW パッケージガイドライン - ArchWiki
    https://wiki.archlinux.jp/index.php/MinGW_%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3
     
    MinGW-w64 - for 32 and 64 bit Windows / Wiki2 / UsingLinuxBinaries
    https://sourceforge.net/p/mingw-w64/wiki2/UsingLinuxBinaries/
     
    cross-compiling tinc for 64-bit Windows under Linux using MinGW
    https://www.tinc-vpn.org/examples/cross-compiling-64-bit-windows-binary/
     
    GCCの最適化 - Gentoo Wiki
    https://wiki.gentoo.org/wiki/GCC_optimization/ja
     
    Safe CFLAGS - Gentoo Wiki
    https://wiki.gentoo.org/wiki/Safe_CFLAGS
     
    Using the GNU Compiler Collection (GCC): Environment Variables - GNUオペレーティング・システムと自由ソフトウェア運動
    https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
     
    build - GCC and linking environment variables and flags - Stack Overflow
    https://stackoverflow.com/questions/16044020/gcc-and-linking-environment-variables-and-flags
     
    CXXFLAGSとCPPFLAGSの違い – かひわし4v1.memo
    https://khws4v1.myhome.cx/article/2017/05/cxxflags%E3%81%A8cppflags%E3%81%AE%E9%81%95%E3%81%84/
     
    GNU make: Implicit Variables - GNUオペレーティング・システムと自由ソフトウェア運動
    https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
     
    configureするときのLDFLAGSやLIBSとは - QA@IT
    https://qa.atmarkit.co.jp/q/334
     
    libtool - Qiita
    https://qiita.com/false-git@github/items/a21dbd0f25d8cc91d017
     
    Man page of LIBTOOL - JM Project (Japanese)
    https://linuxjm.osdn.jp/html/gnumaniak/man1/libtool.1.html
     
    linux – .so、.la、.aライブラリファイルの違いは何ですか? - コードログ
    https://codeday.me/jp/qa/20181201/27060.html
     
    linux – libtoolの.laファイルは何ですか? - コードログ
    https://codeday.me/jp/qa/20181127/26644.html
     
    pkg-config-PKG_CONFIG_PATH環境変数 - コードログ
    https://codeday.me/jp/qa/20190808/1400364.html
     
    m32、m64 - インテル(R) C++ コンパイラー・ドキュメント
    http://www2.kobe-u.ac.jp/~lerl2/l_cc_p_10.1.008/doc/main_cls/mergedProjects/copts_cls/common_options/option_m32_m64.htm
     
    gcc(1): GNU project C/C++ compiler - Linux man page
    https://linux.die.net/man/1/gcc
     
    Man page of GCC - JM Project (Japanese)
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html
     
    uname(1): print system info - Linux man page
    https://linux.die.net/man/1/uname
     
    Man page of UNAME - JM Project (Japanese)
    https://linuxjm.osdn.jp/info/GNU_coreutils/coreutils-ja_161.html#uname-invocation
     
    Man page of SED - JM Project (Japanese)
    https://linuxjm.osdn.jp/html/GNU_sed/man1/sed.1.html
     
    sed, a stream editor - GNUオペレーティング・システムと自由ソフトウェア運動
    https://www.gnu.org/software/sed/manual/sed.html
     
    逆引きUNIXコマンド/sedを使ってスペースの文字列操作を行う - Linuxと過ごす
     
    sed スペース 文字列処理(空白文字の整理・空白行の削除) – バイオインフォ 道場 [bioinfo-Dojo]
     
    mpg123 と midnightcommander 及び zangband の ./configure --help より
    System types:
      --build=BUILD     configure for building on BUILD [guessed]
      --host=HOST       cross-compile to build programs to run on HOST [BUILD]
    
    Some influential environment variables:
      CC          C compiler command
      CFLAGS      C compiler flags
      LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
                  nonstandard directory <lib dir>
      LIBS        libraries to pass to the linker, e.g. -l<library>
      CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
                  you have headers in a nonstandard directory <include dir>
      CPP         C preprocessor
      PKG_CONFIG  path to pkg-config utility
      PKG_CONFIG_PATH
                  directories to add to pkg-config's search path
      PKG_CONFIG_LIBDIR
                  path overriding pkg-config's built-in search path
    Use these variables to override the choices made by `configure' or to help
    it to find libraries and programs with nonstandard names/locations.
    


     
    cat /usr/bin/x86_64-w64-mingw32-configure
    #!/bin/sh
    
    # check if last arg is a path to configure, else use parent
    for last; do true; done
    if test -x "${last}/configure"; then
      config_path="$last"
    else
      config_path=".."
    fi
    
    default_mingw_pp_flags="-D_FORTIFY_SOURCE=2"
    default_mingw_compiler_flags="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4"
    default_mingw_linker_flags="-Wl,-O1,--sort-common,--as-needed"
    
    export CPPFLAGS="${MINGW_CPPFLAGS:-$default_mingw_pp_flags $CPPFLAGS}"
    export CFLAGS="${MINGW_CFLAGS:-$default_mingw_compiler_flags $CFLAGS}"
    export CXXFLAGS="${MINGW_CXXFLAGS:-$default_mingw_compiler_flags $CXXFLAGS}"
    export LDFLAGS="${MINGW_LDFLAGS:-$default_mingw_linker_flags $LDFLAGS}"
    
    ${config_path}/configure \
      --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --build="$CHOST" \
      --prefix=/usr/x86_64-w64-mingw32 --libdir=/usr/x86_64-w64-mingw32/lib --includedir=/usr/x86_64-w64-mingw32/include \
      --enable-shared --enable-static "$@"
    

    コンパイラオプションについて

    主に JM Project の Man page of GCC 及び Using the GNU Compiler Collection (GCC) より引用しています。

    CFLAGS,CXXFLAGS で指定したもの

    CFLAGS,CXXFLAGS で指定したもの

    -O2

    -O1

    最適化を行います。最適化コンパイルは幾分長めの処理時間と、大きな関数に対 する非常に多くのメモリを必要とします。

    `-O' が指定されなかった場合は、コンパイラの目標はコンパイルのコストを 低減することや、目的の結果を得るためのデバッグを可能とすることに置かれ ます。それぞれの文は独立しています。つまり、ブレークポイントでプログラムを 停止させることによって、任意の変数に新し い値を代入したり、プログラムカウンタを他の文へと変更することを可能とし、 そのソースコードにプログラマが望む正しい結果を得ることを可能にします。

    `-O' を指定しなかった場合は、register と宣言した変数のみがレジスタへと割り当てられます。コンパイルの結果と して得られるコードは、PCC を `-O' なしで使用した場合と比較して若干良くないものとなります。

    `-O' が指定されると、コンパイラはコードのサイズと実行時間を減少させる ことを試みます。

    `-O' を指定することによって、 `-fthread-jumps' と `-fdefer-pop' のフラグが指定されます。遅延スロットをもつマシンでは `-fdelayed-branch' が指定されます。フレームポインタを使わないデバッグをサポートしている マシンでは、`-fomit-frame-pointer' も指定されます。マシンによってはさらにその他のフラグが 指定されることもあります。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    -O2

    さらに最適化を行います。サポートされている最適化手段のうち、 空間と速度のトレードオフを含まないものはほとんどの全て使用されます。 例えばループのアンローリングや関数のインライン化は行われません。 -O と比較して、このオプションはコンパイル時間と生成コードの性能の双方を増加 させます。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    -pipe

    -pipe

    コンパイル時のステージの間のデータの受け渡しに、テンポラリファイルではなく パイプを使用します。いくつかのシステムではアセンブラがパイプからの入力を受け 付けることができないために、このオプションを指定すると失敗します。 GNU アセンブラでは問題なく使用できます。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    -fno-plt

    -fno-plt

    Do not use the PLT for external function calls in position-independent code. Instead, load the callee address at call sites from the GOT and branch to it. This leads to more efficient code by eliminating PLT stubs and exposing GOT loads to optimizations. On architectures such as 32-bit x86 where PLT stubs expect the GOT pointer in a specific register, this gives more register allocation freedom to the compiler. Lazy binding requires use of the PLT; with -fno-plt all external symbols are resolved at load time.

    Alternatively, the function attribute noplt can be used to avoid calls through the PLT for specific external functions.

    In position-dependent code, a few targets also convert calls to functions that are marked to not use the PLT to use the GOT instead.
    https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

    -fexceptions

    -fexceptions

    Enable exception handling. Generates extra code needed to propagate exceptions. For some targets, this implies GCC generates frame unwind information for all functions, which can produce significant data size overhead, although it does not affect execution. If you do not specify this option, GCC enables it by default for languages like C++ that normally require exception handling, and disables it for languages like C that do not normally require it. However, you may need to enable this option when compiling C code that needs to interoperate properly with exception handlers written in C++. You may also wish to disable this option if you are compiling older C++ programs that don’t use exception handling.
    https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

    --param=ssp-buffer-size=4

    ssp-buffer-size

    The minimum size of buffers (i.e. arrays) that receive stack smashing protection when -fstack-protection is used.
    https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

    -static

    -static

    ダイナミックリンクをサポートするシステムにおいて、このオプションは共有 ライブラリとのリンクを抑制します。それ以外のシステムではこのオプションは 意味を持ちません。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    CPPFLAGS で指定したもの

    CPPFLAGS で指定したもの

    -D_FORTIFY_SOURCE=2

    FORTIFY_SOURCE — Idea of the day
    https://idea.popcount.org/2013-08-15-fortify_source/

    ※ アセンブラ言語や BrainFu*k の持ってる剥き出しのチューリングマシン感だけでご飯3杯はいけます(何

    IPA ISEC セキュア・プログラミング講座:C/C++言語編 第10章 著名な脆弱性対策:バッファオーバーフロー: #4 あふれを検出するデバッグ
    https://www.ipa.go.jp/security/awareness/vendor/programmingv2/contents/c904.html

    GCC にコンパイルオプション -D_FORTIFY_SOURCE=1 あるいは =2 を指定すると、あふれを起こしやすい strcpy() のような関数がマクロ展開によって同様な処理を行うが領域あふれを検査するよう対策された別の関数 __strcpy_chk() に置き換わる。
    プログラム実行時にあふれ等の問題が検出されたときは、プロセスの実行が abort()によって中止される。

    この方法を使うと、ソースコードを変更する必要がなく、コンパイルのし直しのみであふれ検出機能をはたらかせることができる。

    GCCに指定するオプション: -O1 -D_FORTIFY_SOURCE=1 または =2

    この機能を使用するときは、コンパイラの最適化オプションを -O1 またはそれ以上のレベルで指定する必要がある。

    -I/usr/x86_64-w64-mingw32/include

    -Idir

    ディレクトリ dir を、インクルードファイルの検索するディレクトリのリスト中に追加します。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    LDFLAGS で指定したもの

    LDFLAGS で指定したもの

    -Wl,-O1,--sort-common,--as-needed

    -Wl,option

    オプション option をリンカに渡します。option がコンマを含む場合は、それらのコンマで複数のオプションとして分割されます。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    -O level

    If level is a numeric values greater than zero ld optimizes the output. This might take significantly longer and therefore probably should only be enabled for the final binary. At the moment this option only affects ELF shared library generation. Future releases of the linker may make more use of this option. Also currently there is no difference in the linker's behaviour for different non-zero values of this option. Again this may change with future releases.
    https://linux.die.net/man/1/ld

    -sort-common

    通常 ld がグローバルな共通シンボルをそれぞれの出力セクションに配置するにあたっ ては、それらはサイズによってソートされる。まず 1 バイト変数のシンボル、 ついで 2 バイト、 4 バイト変数のシンボル、最後にそれ以外のものが並ぶ。 このオプションはアラインメントによって生じてしまうシンボル間のギャップ を防止する。このオプションはソートを行わないようにする。
    https://linuxjm.osdn.jp/html/GNU_binutils/man1/ld.1.html

    --as-needed
    --no-as-needed

    This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on the command line after the --as-needed option. Normally the linker will add a DT_NEEDED tag for each dynamic library mentioned on the command line, regardless of whether the library is actually needed or not. --as-needed causes a DT_NEEDED tag to only be emitted for a library that satisfies an undefined symbol reference from a regular object file or, if the library is not found in the DT_NEEDED lists of other libraries linked up to that point, an undefined symbol reference from another dynamic library. --no-as-needed restores the default behaviour.
    https://linux.die.net/man/1/ld

    -L/usr/x86_64-w64-mingw32/lib

    -Ldir

    ディレクトリdir を `-l' による検索が行なわれるディレクトリのリストに加えます。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    -llibrary

    名前が library であるライブラリをリンク時に使用します。

    リンカは、標準のライブラリ用ディレクトリのリスト中から、 実際のファイル名が `liblibrary.a' であるファイルを検索します。リンカはこのファイルを、ファイル 名で直接指定した場合と同様に使用します。

    検索するディレクトリには、いくつかの標準システムディレクトリと、`-L' によって指定したディレクトリが含まれます。

    通常、この方法で発見されるファイルはライブラリファイル、つまりいくつかの オブジェクトファイルをメンバとして含むアーカイブファイルです。 リンカは、アーカイブファイルの中を検索して、 参照されているが定義されていないシンボルを定義しているメンバを 探し出します。 しかし、もしリンカがライブラリでなく通常のオブジェクトファイルを発見した 場合は、そのオブジェクトファイルを通常の方法でリンクします。`-l' オプションを使用する場合とファイル名を直接指定する場合の違いは、`-l' の場合が library を `lib' と `.a' で囲み、いくつものディレクトリを検索することだけです。
    https://linuxjm.osdn.jp/html/GNU_gcc/man1/gcc.1.html

    実際の運用

    直接ソースコードをコンパイルする場合

    手順:

    1. activate-mingw64 する

    2. 必要に応じたオプションを渡しコンパイルする

    $CC $CFLAGS -o hoge.exe hoge.c $CPPFLAGS $LDFLAGS
    

    MAN/INFOPAGE

    参考とした文献

    参考とした文献

     
    sl の Makefile
     
    pacman4console の Makefile

    3. 生成物をCドライブにコピーする

    mkdir -p /mnt/c/Users/Public/fuga
    cp hoge.exe /mnt/c/Users/Public/fuga/
    

    MAN/INFOPAGE

    4. deactivate-mingw64 する

    参考とした文献

    参考とした文献

     
    リンカ – mingwを使用したx86_64-w64用のcairoのクロスコンパイル - コードログ
    https://codeday.me/jp/qa/20190425/694551.html
     
    ほげ (hoge)とは|「分かりそう」で「分からない」でも「分かった」気になれるIT用語辞典
    https://wa3.i-3-i.info/word11871.html

    例:

    例:sl

    sl
    https://github.com/mtoyoda/sl

    構築依存のインストール

    構築依存のインストール
    yay
    yay -S mingw-w64-ncurses
    

    依存パッケージは mingw-w64-libiconv を指定。mingw-w64-win-iconv は現在メンテナ不在(Orphaned)。

    ソースのダウンロードと展開

    ソースのダウンロードと展開
    mkdir -p $HOME/Downloads/sl
    cd $HOME/Downloads/sl
    curl -LO https://github.com/mtoyoda/sl/archive/5.02.tar.gz
    tar zxf 5.02.tar.gz
    cd sl-5.02
    

    ビルド

    ビルド
    activate-mingw64
    $CC $CFLAGS -o sl sl.c -lncurses $CPPFLAGS
    deactivate-mingw64
    

    Cドライブにコピー

    C:¥Users¥Publicにコピー
    mkdir -p /mnt/c/Users/Public/sl
    cp -a ../sl-5.02 /mnt/c/Users/Public/sl/
    

    ./configure, make, make install, の場合

    手順:

    1. 必要に応じたオプションを渡し mingw-w64-configure する

    1-a

    ダウンロードし展開したソースで以下を実行します。

    mkdir build && cd build
    x86_64-w64-mingw32-configure
    

    MAN/INFOPAGE

     
    mkdir
    https://linuxjm.osdn.jp/html/GNU_coreutils/man1/mkdir.1.html
     
    cd
    https://linuxjm.osdn.jp/html/GNU_bash/man1/builtins.1.html
     
    x86_64-w64-mingw32-configure
    cat /usr/bin/x86_64-w64-mingw32-configure
    #!/bin/sh
    
    # check if last arg is a path to configure, else use parent
    for last; do true; done
    if test -x "${last}/configure"; then
      config_path="$last"
    else
      config_path=".."
    fi
    
    default_mingw_pp_flags="-D_FORTIFY_SOURCE=2"
    default_mingw_compiler_flags="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4"
    default_mingw_linker_flags="-Wl,-O1,--sort-common,--as-needed"
    
    export CPPFLAGS="${MINGW_CPPFLAGS:-$default_mingw_pp_flags $CPPFLAGS}"
    export CFLAGS="${MINGW_CFLAGS:-$default_mingw_compiler_flags $CFLAGS}"
    export CXXFLAGS="${MINGW_CXXFLAGS:-$default_mingw_compiler_flags $CXXFLAGS}"
    export LDFLAGS="${MINGW_LDFLAGS:-$default_mingw_linker_flags $LDFLAGS}"
    
    ${config_path}/configure \
      --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --build="$CHOST" \
      --prefix=/usr/x86_64-w64-mingw32 --libdir=/usr/x86_64-w64-mingw32/lib --includedir=/usr/x86_64-w64-mingw32/include \
      --enable-shared --enable-static "$@"
    


    1-b

    build ディレクトリから x86_64-w64-mingw32-configure 出来ないもの(../configure でエラーを起こすもの)については展開したソースのルートディレクトリで以下を実行します。

    x86_64-w64-mingw32-configure ./configure
    

    MAN/INFOPAGE

     
    x86_64-w64-mingw32-configure
    cat /usr/bin/x86_64-w64-mingw32-configure
    #!/bin/sh
    
    # check if last arg is a path to configure, else use parent
    for last; do true; done
    if test -x "${last}/configure"; then
      config_path="$last"
    else
      config_path=".."
    fi
    
    default_mingw_pp_flags="-D_FORTIFY_SOURCE=2"
    default_mingw_compiler_flags="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4"
    default_mingw_linker_flags="-Wl,-O1,--sort-common,--as-needed"
    
    export CPPFLAGS="${MINGW_CPPFLAGS:-$default_mingw_pp_flags $CPPFLAGS}"
    export CFLAGS="${MINGW_CFLAGS:-$default_mingw_compiler_flags $CFLAGS}"
    export CXXFLAGS="${MINGW_CXXFLAGS:-$default_mingw_compiler_flags $CXXFLAGS}"
    export LDFLAGS="${MINGW_LDFLAGS:-$default_mingw_linker_flags $LDFLAGS}"
    
    ${config_path}/configure \
      --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --build="$CHOST" \
      --prefix=/usr/x86_64-w64-mingw32 --libdir=/usr/x86_64-w64-mingw32/lib --includedir=/usr/x86_64-w64-mingw32/include \
      --enable-shared --enable-static "$@"
    


    1-c

    configure スクリプトが --enable-shared や --enable-static を受け付けず x86_64-w64-mingw32-configure動作しない場合は activate-mingw64 を実行し、その後

    ./configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --build="$CHOST" --prefix=/usr/x86_64-w64-mingw32 --libdir=/usr/x86_64-w64-mingw32/lib --includedir=/usr/x86_64-w64-mingw32/include
    

    等、x86_64-w64-mingw32-configure の記述から問題となるオプションを抜いて configure スクリプトを実行します。

    host/target の詳細についてはこちらを参照ください

     
    cross compiling - What's the difference of "./configure" option "--build", "--host" and "--target"? - Stack Overflow
    https://stackoverflow.com/questions/5139403/whats-the-difference-of-configure-option-build-host-and-target
     
    GNU Compiler Collection (GCC) Internals: Configure Terms
    https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
     
    Host/Target specific installation notes for GCC - GNU Project - Free Software Foundation (FSF)
    https://gcc.gnu.org/install/specific.html

    3.makeする

    make_する
    make -j$(grep processor /proc/cpuinfo | wc -l)
    

    MAN/INFOPAGE

    ※ mingw32-make に -j$(nproc)-j$(grep processor /proc/cpuinfo | wc -l) を渡すことで、構築時間の短縮を期待できます。

    4.make installする

    make_install_する
    #カレントディレクトリに "install" ディレクトリを作り、そこにインストールする。
    make DESTDIR=$(pwd)/install install
    

    MAN/INFOPAGE

    5. 生成物をCドライブにコピーする

    Windows の各ドライブは WSL 側で /mnt 以下からアクセス可能です。

    6.(activate-mingw64した場合)忘れずにdeactivate-mingw64する

    参考とした文献

    参考とした文献

     
    aur.git - AUR Package Repositories
    https://aur.archlinux.org/cgit/aur.git/commit/?h=mingw-w64-configure&id=ba97829aad400afa7c197a74dbcdb92b8778c8fb
     
    make install のインストール先を指定する - Engineer in garage
    http://shocrunch.hatenablog.com/entry/2014/12/04/204242
     
    OpenOCDをwslでWindows用にクロスコンパイルする - Qiita
    https://qiita.com/qawsed477/items/2f93f2c1ff0de6fef038
     
    cross-compiling tinc for 64-bit Windows under Linux using MinGW
    https://www.tinc-vpn.org/examples/cross-compiling-64-bit-windows-binary/
     
    AUR (en) - mingw-w64-configure
    https://aur.archlinux.org/packages/mingw-w64-configure/
     
    MinGW - Fedora Project Wiki
    https://fedoraproject.org/wiki/MinGW
     
    MinGW/Tutorial - Fedora Project Wiki
    https://fedoraproject.org/wiki/MinGW/Tutorial
     
    MinGW package guidelines - ArchWiki
    https://wiki.archlinux.org/index.php/MinGW_package_guidelines
     
    Cross-compiling tools package guidelines - ArchWiki
    https://wiki.archlinux.org/index.php/Cross-compiling_tools_package_guidelines
     
    MinGW パッケージガイドライン - ArchWiki
    https://wiki.archlinux.jp/index.php/MinGW_%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3
     
    CHOSTの変更 - Gentoo Wiki
    https://wiki.gentoo.org/wiki/Changing_the_CHOST_variable/ja
     
    Host/Target specific installation notes for GCC - GNU Project - Free Software Foundation (FSF)
    https://gcc.gnu.org/install/specific.html
     
    GNU Compiler Collection (GCC) Internals: Configure Terms
    https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
     
    cross compiling - What's the difference of "./configure" option "--build", "--host" and "--target"? - Stack Overflow
    https://stackoverflow.com/questions/5139403/whats-the-difference-of-configure-option-build-host-and-target
     
    物理 CPU、CPU コア、および論理 CPU の数を確認する - Red Hat Customer Portal
    https://access.redhat.com/ja/solutions/2159401
     
    Man page of NPROC - JM Project
    https://linuxjm.osdn.jp/html/GNU_coreutils/man1/nproc.1.html

    例:

    例:wxWidgets
    ソースのダウンロードと展開
    ソースのダウンロードと展開
    mkdir -p $HOME/Downloads/wxWidgets
    cd $HOME/Downloads/wxWidgets
    curl -LO https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.2/wxWidgets-3.1.2.tar.bz2
    tar jxf wxWidgets-3.1.2.tar.bz2
    cd wxWidgets-3.1.2
    mkdir build_win && cd build_win
    
    ビルド
    ビルド
    activate-mingw64
    ../configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --build="$CHOST" --prefix=/usr/x86_64-w64-mingw32 --libdir=/usr/x86_64-w64-mingw32/lib --includedir=/usr/x86_64-w64-mingw32/include --with-msw --disable-shared
    make -j$(grep processor /proc/cpuinfo | wc -l)
    make DESTDIR=$(pwd)/install install
    deactivate-mingw64
    
    Cドライブにコピー
    C:¥Users¥Publicにコピー
    mkdir -p /mnt/c/Users/Public/wxWidgets
    cp -a ../../wxWidgets-3.1.2 /mnt/c/Users/Public/wxWidgets/
    

    ※ 生成済みバイナリの動作検証は行っていません。ごめんなさい。

    cmake, ninja, ninja install, の場合

    手順:

    1. cmake 及び ninja を導入する

    cmakeとninjaの導入
    yay
    yay -S mingw-w64-cmake ninja
    

    MAN/INFOPAGE

    2. x86_64-w64-mingw32-cmake の実行

    展開したソースで以下を実行します。

    x86_64-w64-mingw32-cmakeの実行例
    mkdir build && cd build
    x86_64-w64-mingw32-cmake -G "Ninja" -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$(pwd)/install ..
    # CMAKE_INSTALL_PREFIX でカレントディレクトリの install 以下にインストールよう指定
    

    MAN/INFOPAGE

    ※ 環境変数 CFLAGS や CXXFLAGS で指定する値は CMake の場合 CMAKE_<LANG>_FLAGS で指定します。例えば -D CMAKE_C_FLAGS="-static -m64" -D CMAKE_CXX_FLAGS="-static -m64" などとします。

    3. ninja の実行

    ninja
    

    MAN/INFOPAGE

    make とは異なり、ninja は標準でマルチスレッド動作です。場合によっては ninja -j(grep processor /proc/cpuinfo | wc -l) で ninja のスレッド数と論理 CPU の数を一致させても良いかもしれません。

    4. ninja install の実行

    ninja install
    

    MAN/INFOPAGE

    5. 生成物をCドライブにコピーする

    Windows の各ドライブは WSL 側で /mnt 以下からアクセス可能です。

    参考とした文献

    参考とした文献

     
    Passing compiler options cmake - Stack Overflow
    https://stackoverflow.com/questions/44284275/passing-compiler-options-cmake
     
    c++ - How do I add a linker or compile flag in a CMake file? - Stack Overflow
    https://stackoverflow.com/questions/11783932/how-do-i-add-a-linker-or-compile-flag-in-a-cmake-file
     
    CMAKE_<LANG>_FLAGS — CMake 3.16.0-rc3 Documentation
    https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html
     
    Run a Command-Line Tool - cmake(1) — CMake 3.16.0-rc3 Documentation
    https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool
     

    cmake -E help
    $ cmake -E help
    CMake Error: cmake version 3.15.5
    Usage: cmake -E <command> [arguments...]
    Available commands:
      capabilities              - Report capabilities built into cmake in JSON format
      chdir dir cmd [args...]   - run command in a given directory
      compare_files [--ignore-eol] file1 file2
                                  - check if file1 is same as file2
      copy <file>... destination  - copy files to destination (either file or directory)
      copy_directory <dir>... destination   - copy content of <dir>... directories to 'destination' directory
      copy_if_different <file>... destination  - copy files if it has changed
      echo [<string>...]        - displays arguments as text
      echo_append [<string>...] - displays arguments as text but no new line
      env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...
                                - run command in a modified environment
      environment               - display the current environment
      make_directory <dir>...   - create parent and <dir> directories
      md5sum <file>...          - create MD5 checksum of files
      sha1sum <file>...         - create SHA1 checksum of files
      sha224sum <file>...       - create SHA224 checksum of files
      sha256sum <file>...       - create SHA256 checksum of files
      sha384sum <file>...       - create SHA384 checksum of files
      sha512sum <file>...       - create SHA512 checksum of files
      remove [-f] <file>...     - remove the file(s), use -f to force it
      remove_directory <dir>... - remove directories and their contents
      rename oldname newname    - rename a file or directory (on one volume)
      server                    - start cmake in server mode
      sleep <number>...         - sleep for given number of seconds
      tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]
                                - create or extract a tar or zip archive
      time command [args...]    - run command and display elapsed time
      touch <file>...           - touch a <file>.
      touch_nocreate <file>...  - touch a <file> but do not create it.
      create_symlink old new    - create a symbolic link new -> old
    

    例:

    例:OpenCV
    構築依存のインストール
    構築依存のインストール
    yay
    yay -S mingw-w64-cmake ninja
    

    mingw-w64-freeglut を導入し、CMake のオプションに -D WITH_OPENGL=ON を渡すことで、OpenGL 対応ビルドが可能でした。

    ソースのダウンロードと展開
    ソースのダウンロードと展開
    mkdir -p $HOME/Downloads/OpenCV
    cd $HOME/Downloads/OpenCV
    curl -LO https://github.com/opencv/opencv/archive/4.1.2.tar.gz
    tar zxf 4.1.2.tar.gz
    cd opencv-4.1.2
    mkdir build && cd build
    
    ビルド
    ビルド
    x86_64-w64-mingw32-cmake -G "Ninja" -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$(pwd)/install ..
    ninja -j$(grep processor /proc/cpuinfo | wc -l)
    ninja install
    
    Cドライブにコピー
    C:¥Users¥Publicにコピー
    mkdir -p /mnt/c/Users/Public/OpenCV
    cp -a ../../opencv-4.1.2 /mnt/c/Users/Public/OpenCV/
    

    QMake(Qt系)

    mingw-w64-qt5-basemingw-w64-qt4QMake を使用する。

    WSLtty

    公式 GitHub
    https://github.com/mintty/wsltty/

    README
    https://github.com/mintty/wsltty/blob/master/README.md

    Release ページ
    https://github.com/mintty/wsltty/releases

    image.png

    何かと高機能で便利です。しかも Sixel Graphics を表示可能だったりします。

    ※ フォント指定によっては画像表示が化けました。手元の環境では Noto Mono の 10pt 以上で問題なく表示出来ました。

    参考とした文献

    参考とした文献

    WSLのコンソールを便利で高機能な「wsltty」に置き換える:Tech TIPS - @IT
    https://www.atmarkit.co.jp/ait/articles/1812/13/news031.html

    The Rest of the Lenna Story
    http://www.lenna.org/

    SIXEL - Qiita
    https://qiita.com/tags/sixel

    libsixel | The new standard of SIXEL development
    https://saitoha.github.io/libsixel/

    Mintty and use case examples · Issue #50 · saitoha/libsixel · GitHub
    https://github.com/saitoha/libsixel/issues/50

    AUR (en) - libsixel
    https://aur.archlinux.org/packages/libsixel/

    長編まとめ・Sixel Graphics復活への動き(1) - Togetter
    https://togetter.com/li/375434

    余談

    あとがき

    オープンソースソフトウェアのファンのひとりとして WSL2 の盛り上がりは嬉しいのですが(WSL2 の Linux カーネルはオープンソースであることですし)、その一方で、Cygwin のユーザー層が食われてしまうと、cygwin1.dll から msys-2.0.dll を作っている MSYS2 や、MSYS2 を使っていると思われる Git BASH にも影響がありそうで不安です(バグレポが減少することになれば開発にとって痛手かと)。この不安は本記事の執筆動機のひとつでもあります。

    ところで、システムコール翻訳型からハイパーバイザー+ネイティブカーネル型にすることで性能や互換性の向上が見込めるなら、例えば ReactOSKVM で動かしてアプリケーション側に Windows API を提供すれば、Linux で Wine を超える使い勝手を狙えたりするのでしょうか。興味は尽きません。

    欲を言えば、WSL1 がオープンソースになるとインパクトが大きそう(MSYS2 や Cygwin が活気付きそう)で楽しいのですが、これについては期待を抱くに留めておきます。

    本稿執筆時の BGM

    執筆時 BGM

    関連する文献

    関連する文献

     
    絶対に作業できない作業用BGMサイト - Qiita
    https://qiita.com/de_teiu_tkg/items/6ebcef3550507258edaf
     
    進捗がなかったらメンターが現れるATOM - Qiita
    https://qiita.com/iwamatsu0430/items/8e19995d3eedf1d6a823

    yay でインストール可能な Pac-Man 風ゲーム+α

    Pac-Man 風ゲーム+α

    Curses 系のゲームをインストールすれば WSL を軽量レトロゲームコンソールとして活用出来そうです。

    • aur/njam

      • description: Full-featured cross-platform pacman-like game
    • aur/myman

      • description: Pacman clone with an ncurses and a graphic interface
    • aur/notpacman

    • aur/pacman_sdl

      • description: Pacman clone using SDL. Guide Pacman through a maze and collect pac-dots while avoiding ghosts.
    • aur/pacman4console

      • description: A 9 level ncurses pacman game with editor, patched not to disturb our package manager and to have nice ghosts
    • aur/pacmantheme

      • description: pacmantheme - play the pacman theme song with the motherboard buzzer
      • マザボのブザーで鳴らすので、ブザー機能付きマザボに Arch を実機インストールする必要がありそうです。
    • aur/pacapong

      • description: game combining pong, pacman and space invaders

    Orphaned(メンテナ不在)

    • aur/xpacman

      • description: X pacman game (use z x / ' q keys)
    • aur/xpacman2

      • description: another X pacman game
    • aur/pacman_sdl-ebuc99-git

      • description: Pacman clone using SDL. Guide Pacman through a maze and collect pac-dots while avoiding ghosts. (ebuc99 fork)

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3