3

Thanks for any help with this issue, I know there's a lot of different threads around ruby sqlite3 gem install issues. However, I'm facing a specific issue, where by all appearances, it seems sqlite3 is installed on my system, yet unable to be found by the ruby sqlite3 gem install.

I've outlined below that I'm able to see sqlite3 installed on my system, yet I get an error when trying to gem install sqlite3:

checking for sqlite3_libversion_number() in -lsqlite3... no

sqlite3 is missing. Try 'brew install sqlite3', 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev' and check your shared library search path (the location where your sqlite3 shared library is located).

I seem to get this same error, even if I use the: --with-sqlite3-dir option, setting it to the directory I see in which sqlite3.

Does anyone know what I'm doing wrong, why the sqlite3 ruby gem can't find my system sqlite3 library? Do I need to update something else somewhere, or something in the errors I'm overlooking? Any help is graciously appreciated!

Details below:


Verify sqlite3 is installed on my system (macOS)

sqlite3 --version
> 3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5
which sqlite3
> /opt/homebrew/opt/sqlite/bin/sqlite3

Attempt to install the sqlite3 gem

However, if I attempt to install the gem file via:

gem install sqlite3

I get the error:

sqlite3 is missing

Full output:

twknab@tk-mac-mini my-cool-project % gem install sqlite3
Building native extensions. This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: /Users/twknab/.rvm/gems/ruby-3.0.2/gems/sqlite3-1.4.2/ext/sqlite3
/Users/twknab/.rvm/rubies/ruby-3.0.2/bin/ruby -I /Users/twknab/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0 -r ./siteconf20211113-2417-45lgod.rb extconf.rb
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... yes
checking for -ldl... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/twknab/.rvm/rubies/ruby-3.0.2/bin/$(RUBY_BASE_NAME)
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib
        --with-pthread-dir
        --without-pthread-dir
        --with-pthread-include
        --without-pthread-include=${pthread-dir}/include
        --with-pthread-lib
        --without-pthread-lib=${pthread-dir}/lib
        --with-pthreadlib
        --without-pthreadlib
        --with-dl-dir
        --without-dl-dir
        --with-dl-include
        --without-dl-include=${dl-dir}/include
        --with-dl-lib
        --without-dl-lib=${dl-dir}/lib
        --with-dllib
        --without-dllib
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3lib
        --without-sqlite3lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/twknab/.rvm/gems/ruby-3.0.2/extensions/arm64-darwin-21/3.0.0/sqlite3-1.4.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/twknab/.rvm/gems/ruby-3.0.2/gems/sqlite3-1.4.2 for inspection.
Results logged to /Users/twknab/.rvm/gems/ruby-3.0.2/extensions/arm64-darwin-21/3.0.0/sqlite3-1.4.2/gem_make.ou

Installing sqlite3 gem but setting directory

I've also tried setting the directory when installing the gem to the same which is returned by which sqlite3, but get the same error saying sqlite3 is not found on my system:

gem install sqlite3 --with-sqlite3-dir=/opt/homebrew/opt/sqlite/bin/sqlite3 

I get the same error:

sqlite3 is missing. Try 'brew install sqlite3', 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev' and check your shared library search path (the location where your sqlite3 shared library is located).

(And the same full output as above)


Other Notes

If I checkout the mkmf.log as noted at the end of the output, I do see some stuff like this:

"pkg-config --exists sqlite3"
| pkg-config --libs sqlite3
=> "-L/opt/homebrew/Cellar/sqlite/3.36.0/lib -lsqlite3\n"
"gcc -fdeclspec -o conftest -I/Users/twknab/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0/arm64-darwin21 -I/Users/twknab/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0/ruby/backward -I/Users/twknab/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/openssl@1.1/include -fno-common -pipe conftest.c  -L. -L/Users/twknab/.rvm/rubies/ruby-3.0.2/lib -L. -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/openssl@1.1/lib -fstack-protector-strong -L/usr/local/lib  -m64   -lruby.3.0   "
ld: warning: ignoring file /Users/twknab/.rvm/rubies/ruby-3.0.2/lib/libruby.3.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }

Specifically noting:

ld: warning: ignoring file /Users/twknab/.rvm/rubies/ruby-3.0.2/lib/libruby.3.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

I'm running on an M1 apple silicon. Any thoughts if this might be part of the problem? Having trouble making sense of these logs

twknab
  • 1,741
  • 1
  • 21
  • 35
  • 1
    Rails only ships with SQLite as its (usually) easy to setup or is preinstalled on many systems - it not a good choice for actually deploying apps. If its giving you trouble then just skip it and use Postgres, MySQL, MariaDB or whatever you intend to actually deploy your application on as the time spent trying to fix this is ultimately wasted. – max Nov 14 '21 at 19:17
  • @max I appreciate this feedback, and is a good thought. I’ll try just swapping sqlite for mysql, as this has been a lot of wrestling! Note: this project is for a debugging / feature assessment, so never will be deployed anyhow and just for learning. The logs in `mkmf.log` makes me wonder if with sqlite3 gem something about the apple silicon makes it not happy? (At least makes me suspect if part of the issue) Thank you so much for your reply! – twknab Nov 14 '21 at 21:03

1 Answers1

2

Could solve it with:

sudo gem install sqlite3 -v '1.4.2' -- --with-sqlite3-lib=/usr/lib

and then:

bundle config build.sqlite3 --with-sqlite3-lib=/usr/lib
Ivo
  • 2,308
  • 1
  • 13
  • 28