LoginSignup
0
1

More than 5 years have passed since last update.

msys2でcppcheckを使おうとしたらlibrary configurationがないと怒られるのは嫌だ

Posted at

はじめに

ふと思い立ってcppcheckをmsys2でも使おうと思った。というわけで

ブログズミ: Cppcheck を使ってみた

を見ながら

$cppcheck --enable=all --std=c99 -x c -v io.c

とかおもむろにコマンドを打ったらですね

cppcheck: Failed to load library configuration file 'std.cfg'. File not found
cppcheck: Failed to load library configuration file 'windows.cfg'. File not found
(information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled with CFGDIR set to "C:/building/msys64/mingw32/share/cppcheck/cfg" and will therefore search for std.cfg in that path.

と怒られました。

1.png

環境

Windows10 x64 msys2

$pacman -Sl | grep pacman
msys pacman 5.0.1-1 [インストール済み]
msys pacman-mirrors 20160112-1 [インストール済み]
$pacman -Sl | grep cppcheck
mingw32 mingw-w64-i686-cppcheck 1.74-1 [インストール済み]
mingw64 mingw-w64-x86_64-cppcheck 1.74-1 [インストール済み]
$cppcheck --version
Cppcheck 1.74

原因

cppcheckには
ブログズミ: [Cppcheck] cfg ファイル設定
に紹介のあるように.cfgファイルが有ります。

msys2のパッケージビルドするときに、デフォルトのconfigファイルのパスを指定するらしいのですが、これが絶対パスしか受け付けないようで、C:/building/msys64/mingw32/share/cppcheck/cfgに固定されてしまったものがpacmanで落ちてくるっぽいです。

対処法

実行ファイルをバイナリエディタで書き換える

2.png

まずは./msys64/mingw[32か64]/binにあるcppcheck.exeを適当なバイナリエディタで開きます

3.png

share/cppcheck/cfgで検索すると、エラーメッセージ用とそうでない方の2箇所ヒットしますが、そうでない方を探して

4.png

書き換えます。文字列は必ずNULL文字で終わらないといけないのがCの仕様なので、ここでも00で終わるようにします
当たり前ですが、それ以降のアドレスがずれないように、長さが増減したらその数に合わせて00のbyte数を調整してください。じゃないと色々壊れます。いや、以降のアドレスを参照する部分を全部書き換えればいいんですが、それくらいならリビルドするほうが早いです。

結果

5.png

やったぜ。

感想

msys2の中の人、相対パスにできるようにパッチ当ててください

0
1
1

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
1