I am trying to package the following ruby script with OCRA (I am on Windows 10, Ruby 2.6):
require 'sqlite3'
puts SQLite3::VERSION
Running this in cmd works properly:
C:\Users\monday\Documents\projects\sqlite3_test>script.rb
1.4.2
When I package script.rb the following way:
ocra --gem-full=sqlite3 --dll sqlite3.dll script.rb --output script.exe --verbose
I have added sqlite3.dll and sqlite3.def to my PATH and into C:\Ruby26-x64\bin as per various suggestions on SO and GitHub.
Here is the error that pops up when I run the resulting script.exe:
C:\Users\monday\Documents\projects\sqlite3_test>script.exe
Traceback (most recent call last):
2: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/src/script.rb:1:in `<main>'
1: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- sqlite3 (LoadError)
6: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/src/script.rb:1:in `<main>'
5: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
4: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
3: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
2: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3.rb:4:in `<top (required)>'
1: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- sqlite3/2.6/sqlite3_native (LoadError)
7: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/src/script.rb:1:in `<main>'
6: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
5: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
4: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
3: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3.rb:2:in `<top (required)>'
2: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3.rb:6:in `rescue in <top (required)>'
1: from C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': 126: The specified module could not be found. - C:/Users/monday/AppData/Local/Temp/ocr7747.tmp/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/sqlite3_native.so (LoadError)
I am sure that lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/sqlite3_native.so is present in the temporary folder, judging by OCRA's output:
...
m lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3.rb
m lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/constants.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/database.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/errors.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/pragmas.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/resultset.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/sqlite3_native.so <<< HERE!
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/statement.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/translator.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/value.rb
a lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2/lib/sqlite3/version.rb
...
What am I missing?
After some research I found out that the error message
The specified module could not be found.means that the program might be missing required DLLs. Now thatsqlite3_native.sois present, I presumed that it is that program that is missing DLLs. Runningdumpbinon it gave the following results:Apparently,
libsqlite3-0.dllwas never detected by OCRA, and thus never moved into temporary folder'sbin/directory. A quick search revealed thatlibsqlite3-0.dllis indeed present on my machine atC:\Ruby26-x64\msys64\mingw64\bin. I moved it toC:\Ruby26-x64\bin, and ran OCRA with the following options:Later, I realized that OCRA is now able to detect this DLL on its own:
So, finally:
Works properly, and there is no need for
sqlite3.dll.This seems to be quite a universal solution, as I was able to make puma run from within OCRA-packaged script by adding required DLLs to Ruby installation's
bin/folder.