less than 1 minute read

sqlite 1.4.2のビルドに失敗したときの対処方法をまとめた。

環境

  • OSおよびバージョン: Windows11 64bit
  • Rubyバージョン: 2.6.3

エラー

> gem install sqlite3 -v '1.4.2'
<略>
Building native extensions. This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: c:/app/lang/ruby/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/ext/sqlite3
c:/app/lang/ruby/Ruby26-x64/bin/ruby.exe -I c:/app/lang/ruby/Ruby26-x64/lib/ruby/2.6.0 -r ./siteconf20231010-14952-8rrf7m.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

原因はsqlite3.hがないためであると判明。

対処

SQLite3公式サイトからソースファイルとDLLファイルをダウンロード。

ソースファイル(sqlite3.h)はsqlite-amalgamation-xxx.zipをダウンロードし、DLLファイル(sqlite3.dll)は自身の端末に適したものをダウンロードする。

ダウンロードしたzipファイルを解凍し、対象ファイルを以下ディレクトリに配置。

なお、解凍すると何個かファイルが格納されてますが、必要なのはsqlite3.h、sqlite3.dllのみ、その2ファイルを以下のディレクトリに格納。

  • sqlite3.h
    • 任意のディレクトリを作成し、格納。例:C:/sqlite3/
  • sqlite3.dll
    • Rubyのbinディレクトリ配下に配置。例:C:\Ruby25-x64\bin

以下で再トライ。この際、–with-sqlite3-includeには②でsqlite3.hを格納した絶対パスを指定し、–with-sqlite3-libにはsqlite3.dllを格納した絶対パスを指定する。

> gem install sqlite3 -v '1.4.2' --platform=ruby -- --with-sqlite3-include=C:/app/db/sqlite3 --with-sqlite3-lib=C:/app/lang/ruby/Ruby26-x64/bin
<略>
Building native extensions with: '--with-sqlite3-include=C:/app/db/sqlite3 --with-sqlite3-lib=C:/app/lang/ruby/Ruby26-x64/bin'
This could take a while...
Successfully installed sqlite3-1.4.2
Parsing documentation for sqlite3-1.4.2
Installing ri documentation for sqlite3-1.4.2
Done installing documentation for sqlite3 after 1 seconds
1 gem installed

参考