rails-sqlserver / tiny_tds

TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
Other
607 stars 189 forks source link

Windows 10 x64 ruby 2.4 cannot load such file -- tiny_tds/tiny_tds #365

Closed NullVoxPopuli closed 7 years ago

NullVoxPopuli commented 7 years ago

tsql -C: 1.3.0 ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]

I've modified the gem so I can actually see the error as the exception isn't caught when require 'tiny_tds/tiny_tds' is called within {gem_path}/tiny_tds.rb.

So, now I have this:

  old_path = ENV['PATH']
  begin
    # Do the same host consolidation as in extconf.rb
    ports_dir = RbConfig::CONFIG['host'].gsub('i686-pc-mingw32', 'i686-w64-mingw32')
    ENV['PATH'] = "#{File.expand_path("../../ports/#{ports_dir}/bin", __FILE__)};#{old_path}"
    require "tiny_tds/#{ver}/tiny_tds"
  rescue LoadError => e
    puts e
    puts '------------------------------'
    require 'tiny_tds/tiny_tds'
  ensure
    ENV['PATH'] = old_path
  end

which outputs this in the terminal:

126: The specified module could not be found.   - C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x64-mingw32/lib/tiny_tds/2.4/tiny_tds.so

but:

$ ls /c/Ruby24-x64/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x64-mingw32/lib/tiny_tds/2.4/
tiny_tds.so*

it exists.

I thought this could this be an issue with invocation via mingw and the path-notation differences...

I get the same error in the command prompt.

NullVoxPopuli commented 7 years ago

I reproduce the error by doing:

irb
irb> require 'tiny_tds'
saleiv commented 7 years ago

Confirmed on Win7 as well.

Current setup: Win7 x64 Ruby 2.4 x32 tiny_tds 1.3.0 x32

(I've also tried x64 Ruby and x64 tiny_tds, with little difference, but this output is the x32 version)

Attempt at debug similar to NullVoxPopuli:

begin
    # Do the same host consolidation as in extconf.rb
    ports_dir = RbConfig::CONFIG['host'].gsub('i686-pc-mingw32', 'i686-w64-mingw32')
    ENV['PATH'] = "#{File.expand_path("../../ports/#{ports_dir}/bin", __FILE__)};#{old_path}"
    puts "#{File.expand_path("../../ports/#{ports_dir}/bin", __FILE__)}"
    require "tiny_tds/#{ver}/tiny_tds"
  rescue LoadError
    require 'tiny_tds/tiny_tds'
  ensure
    ENV['PATH'] = old_path
  end

Output

irb(main):002:0> require 'tiny_tds'
C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/ports/i686-w64-mingw32/bin
C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/ports/i686-w64-mingw32/bin

LoadError: cannot load such file -- tiny_tds/tiny_tds
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/lib/tiny_tds.rb:23:in `rescue in <top (required)>'
        from C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/lib/tiny_tds.rb:26:in `<top (required)>'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `require'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:40:in `require'
        from (irb):2
        from C:/Ruby24/bin/irb.cmd:19:in `<main>'

I've confirmed that the tiny_tds.so exists at: C:\Ruby24\lib\ruby\gems\2.4.0\gems\tiny_tds-1.3.0-x86-mingw32\lib\tiny_tds\2.4

Copying the tiny_tds.so from 2.4 to: C:\Ruby24\lib\ruby\gems\2.4.0\gems\tiny_tds-1.3.0-x86-mingw32\lib\tiny_tds

So that it can be rescued causes the following trace, which I've seen mentioned in other posts:

irb(main):003:0> require 'tiny_tds'
C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/ports/i686-w64-min
gw32/bin
LoadError: 126: The specified module could not be found.   - C:/Ruby24/lib/ruby/
gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/lib/tiny_tds/tiny_tds.so
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/lib/tiny_tds.rb:23:in `rescue in <top (required)>'
        from C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0-x86-mingw32/lib/tiny_tds.rb:26:in `<top (required)>'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from (irb):3
        from C:/Ruby24/bin/irb.cmd:19:in `<main>'

I've seen other posts alluding to the inability to find the .dlls, which I've verified that they exist in: C:\Ruby24\lib\ruby\gems\2.4.0\gems\tiny_tds-1.3.0-x86-mingw32\ports\i686-w64-mingw32\bin

That folder contains:

I'm at complete loss at how to proceed.

metaskills commented 7 years ago

Sorry about the issues. Not sure I have answers ready since the pre compiled Windows binaries were never my strength. That said, have you tried building FreeTDS and/or this gem as needed from source? There are a few ways to do that from installing deps (FreeTDS) in your system like other systems and forcing a non windows gem install with something like gem install tiny_tds --platform=ruby. Another option would be to clone the repo and do what we do on our CI boxes, which is basically a rake build. Another would be to build the gems like we do when pushing to Rubygems. https://github.com/rails-sqlserver/tiny_tds#compiling-gems-for-windows.

The goal is to find if your own compiled gem works for you better than the pre-compiled ones.

saleiv commented 7 years ago

Hello there,

Thanks again for all the effort and support you've put into this library!

I've tried to go with the gem install tiny_tds --platform=ruby with freetds option.

I've placed the freeTDS in C:\freetds.

I've run into the following

C:\>gem install tiny_tds --platform=ruby -- --with-freetds-dir=c:\FreeTDS
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions with: '--with-freetds-dir=c:\FreeTDS'
This could take a while...
ERROR:  Error installing tiny_tds:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1.3.0/ext/tin
y_tds
C:/Ruby24/bin/ruby.exe -r ./siteconf20170628-11096-16ev3b4.rb extconf.rb --with-
freetds-dir=c:\FreeTDS
extconf.rb:14: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
checking for sybfront.h... *** 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=C:/Ruby24/bin/$(RUBY_BASE_NAME)
        --help
        --enable-lookup
        --disable-lookup
        --with-freetds-dir
        --with-freetds-include
        --without-freetds-include=${freetds-dir}/include
        --with-freetds-lib
        --without-freetds-lib=${freetds-dir}/lib
C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:457:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:588:in `try_cpp'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:1095:in `block in have_header'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:945:in `block in checking_for'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:351:in `block (2 levels) in postpone'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:321:in `open'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:351:in `block in postpone'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:321:in `open'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:347:in `postpone'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:944:in `checking_for'
        from C:/Ruby24/lib/ruby/2.4.0/mkmf.rb:1094:in `have_header'
        from extconf.rb:342:in `freetds_usable?'
        from extconf.rb:348:in `<main>'

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

  C:/Ruby24/lib/ruby/gems/2.4.0/extensions/x86-mingw32/2.4.0/tiny_tds-1.3.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby24/lib/ruby/gems/2.4.0/gems/tiny_tds-1
.3.0 for inspection.
Results logged to C:/Ruby24/lib/ruby/gems/2.4.0/extensions/x86-mingw32/2.4.0/tin
y_tds-1.3.0/gem_make.out

Devtools are installed, and it's verified. When trying to run dk install, it warns that it skipped installation because it's already applied in C:\Ruby24.

The whole rake and cloning, I might not be able to do here, but I might do it from home. Sadly, if I cannot make this whole setup simple (eg. no extra cloning, machines etc.) I might not be able to use it for the task at work.

I'll see if I can try other ways at home.

If you have any other suggestions, I'm more than open to hear them and try them here, as this may help anyone else in a corporate environment.

EDIT:

I've also checked that my mingw compiler is properly inserted to path. (It's located in devkit as well). The contents of the above mentioned mkmf.log

"i686-w64-mingw32-gcc -o conftest.exe -IC:/Ruby24/include/ruby-2.4.0/i386-mingw32 -IC:/Ruby24/include/ruby-2.4.0/ruby/backward -IC:/Ruby24/include/ruby-2.4.0 -I. -Ic:\FreeTDS/include -D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -DFD_SETSIZE=2048 -IC:/msys64/mingw32/lib/libffi-3.2.1/include -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64  -march=i686 -mtune=generic -O2 -pipe -IC:/msys64/mingw32/lib/libffi-3.2.1/include  conftest.c  -L. -LC:/Ruby24/lib -Lc:\FreeTDS/lib -L. -pipe      -lmsvcrt-ruby240  -lgmp -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi   "
c:/devkit/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lgmp
collect2.exe: error: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

Anyone have any idea what is -lgmp? I've googled and found that it's part of something easily installed on Linux with apt-get.

larskanis commented 7 years ago

I started an attempt to support RubyInstaller-2.4, but run out of time. I'll try to complete this ASAP.

coderjoe commented 7 years ago

@larskanis Oh wow, many :+1: for not only jumping on this fast, but for starting with a patch to MINGW-packages. If freetds was in the package list building on windows on the rubyinstaller2 chain would be so much easier.

Have you had a time to try the new rubyinstaller2 gemspec library dependency options for gems?

I do have to apologize though, a huge merge just hit master that will likely conflict with your changes. Sorry! Let me know if there's anything I can do to assist with conflicts/problems. :blush:

TvL2386 commented 7 years ago

+1

himmat62 commented 7 years ago

+1

can you please suggest me which tiny_tds and ruby working compatible version should i take as of now ? i really appreciate if anyone can provide me information.

metaskills commented 7 years ago

I'll try to find time to merge this PR (https://github.com/rails-sqlserver/tiny_tds/pull/368) in this weekend and do another release. I guess if needed you can use that branch now if you wanted to and build your own till then.

coderjoe commented 7 years ago

I've merged PR #368. This will be fixed in the next release.

metaskills commented 7 years ago

Closing this issue, I'll be releasing v2.1.0 today. Please reply back if the 2.1.0.pre1 did not help or the full release.

jamsi commented 6 years ago

Adding require 'devkit' to my boot.rb (before require 'bundler/setup') on a Rails 4.2 did the trick with 2.1.0.