0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GNU diff utils を Mingw64 で Windows 向けにコンパイルする

Last updated at Posted at 2025-04-22

契機

サクラエディタで diff 表示用の diff.exe がなくなっていると聞いたので作ってみようと思った

方法

Windws の Fedora remix on WSL2 で Windows 向けにコンパイルする

手順

  1. インストール先、ビルド用のディレクトリを作成
mkdir -p ~/opt/diff

mkdir ~/BUILD
cd ~/BUILD

make install した後に bin ディレクトリから取ってくるので、ダミーのインストールディレクトリも作成しておく。

  1. コンパイラをダウンロード
sudo dnf install mingw64-gcc-c++
  1. ソースをダウンロードして展開
curl -O ftp://ftp.jaist.ac.jp/pub/GNU/diffutils/diffutils-3.12.tar.xz
tar Jxf diffutils-3.12.tar.xz
cd diffutils-3.12
  1. ライブラリの依存を減らすため、スタティックリンクにする
export CFLAGS=-static LDFLAGS=-static
export gl_cv_func_strcasecmp_works=no

下のは gl_cv_func_strcasecmp_worksgnulib の変更で入ったらしい。そのままだとエラーになるので no でも yes でも構わないが、取り合えず no にしておく。
https://savannah.gnu.org/bugs/?66978

  1. configure && make
mingw64-configure --prefix=$HOME/opt/diff --enable-threads=windows
make -j4
  1. エラー発生!
make[2]: Entering directory '/root/BUILD/diffutils-3.12/src'
  CCLD     cmp.exe
  CCLD     diff.exe
  CCLD     diff3.exe
  CC       sdiff.o
sdiff.c: In function 'main':
sdiff.c:577:28: error: passing argument 2 of '_execvp' from incompatible pointer type [-Wincompatible-pointer-types]
  577 |       execvp (diffargv[0], (char **) diffargv);
      |                            ^~~~~~~~~~~~~~~~~~
      |                            |
      |                            char **
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/unistd.h:11,
                 from ../lib/unistd.h:40,
                 from ../lib/time.h:51,
                 from ../lib/sys/stat.h:51,
                 from system.h:27,
                 from sdiff.c:21:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/process.h:78:77: note: expected 'const char * const*' but argument is of type 'char **'
   78 |   _CRTIMP intptr_t __cdecl _execvp(const char *_Filename,const char *const *_ArgList);
      |                                                          ~~~~~~~~~~~~~~~~~~~^~~~~~~~

でも、よく見ると欲しい diff.exe はもう出来ているのでそこから貰ってくる。

  1. strip してデスクトップへコピー
❯ file src/*.exe
src/cmp.exe:   PE32+ executable (console) x86-64, for MS Windows, 19 sections
src/diff.exe:  PE32+ executable (console) x86-64, for MS Windows, 19 sections
src/diff3.exe: PE32+ executable (console) x86-64, for MS Windows, 19 sections
❯ mingw-strip src/*.exe
❯ file src/*.exe
src/cmp.exe:   PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 10 sections
src/diff.exe:  PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 10 sections
src/diff3.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 10 sections
❯ cp src/*.exe ~/winhome/Desktop

これでデスクトップ上に cmp.exe, diff.exe, diff3.exe ができました。ドキュメントは Web から漁れば必要ないでしょう。あとは煮るなり焼くなり適当に!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?