rugged icon indicating copy to clipboard operation
rugged copied to clipboard

Windows + libssh2 not usable

Open mscharley opened this issue 9 years ago • 8 comments

The current solution to pkg-config isn't workable if you need Windows + libssh2 + rugged:

$ pkg-config --libs --static C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\rugged-0.24.0b11\vendor\libgit2\build\libgit2.pc
-LC:/Program -LC:/Ruby22-x64/DevKit-mingw64-64-4.7.2/lib Files (x86)/libgit2/lib -lgit2 -lssh2 -lws2_32 -lbcrypt -lcrypt32

But the hardcoded list of libs going into $LIBS doesn't include -lssh2 so the build fails spectacularly:

linking shared-object rugged/rugged.so
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rugged-0.24.0b11/ext/rugged/../../vendor/libgit2/build/libgit2.a(ssh.c.obj): In function `ssh_error':
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rugged-0.24.0b11/vendor/libgit2/src/transports/ssh.c:51: undefined reference to `libssh2_session_last_error'
// ... You get the idea...
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rugged-0.24.0b11/ext/rugged/../../vendor/libgit2/build/libgit2.a(ssh.c.obj): In function `list_auth_methods':
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rugged-0.24.0b11/vendor/libgit2/src/transports/ssh.c:759: undefined reference to `libssh2_userauth_authenticated'
collect2.exe: error: ld returned 1 exit status
make: *** [rugged.so] Error 1

The solution seems to be using pkg-config. If someone's compiled libssh2 then installing pkg-config from http://sourceforge.net/projects/pkgconfiglite/files/ is pretty easy. I'm just not quite sure how to work around not having pkg-config. Perhaps a bit more smarts to make pkg-config an optional dependency on Windows?

mscharley avatar Jan 03 '16 13:01 mscharley

My current process for getting libssh2 into rugged:

  1. Install DevKit if you haven't already
  2. Download and extract CMake into the devkit.
  3. Get pkg-config-lite (needed to detect libssh2 correctly) http://sourceforge.net/projects/pkgconfiglite/files/
  4. Download latest release of libssh2
    • sh
    • prefix = mingw style path to your DevKit

    • ./configure --prefix=/c/Ruby22-x64/DevKit-mingw64-64-4.7.2 --with-wincng --disable-shared
    • make
    • make install
    • exit
  5. Fix prefix in $RI_DEVKIT\lib\pkg-config\libssh2.pc to a Windows style path.
  6. Rugged from master. Clone, gem build, gem install.
    • At this point the build fails during gem install. cmake detects pkg-config and asks it about libssh2 and builds libgit2 with SSH support but building rugged.so fails since it doesn't try to link against libssh2.

mscharley avatar Jan 03 '16 14:01 mscharley

@mscharley Thanks for the step-by step instructions for building rugged on windows with libssh2! :+1:

I'll take a look later and see what I can do about this.

arthurschreiber avatar Jan 03 '16 16:01 arthurschreiber

@mscharley Can you try adding --enable-shared=no to your ./configure call? That way, a static libssh2 library will be built and linked into your rugged binary.

arthurschreiber avatar Jan 03 '16 16:01 arthurschreiber

--disable-shared does the same thing, I verified that only a .a library was output.

mscharley avatar Jan 03 '16 20:01 mscharley

For posterities sake, if anyone is interested on how I actually got this working I did a writeup here: http://matt.scharley.me/2016/01/rugged-windows.html

mscharley avatar Jan 04 '16 08:01 mscharley

@mscharley How do I do all that on MSYS2 (32-bit)?

jhannwong avatar Mar 26 '18 20:03 jhannwong

@hannwong unfortunately I don't have a Windows system to test on any more but rereading my article I can't see anything there that is obviously 64-bit specific - it should just work on a 32-bit system as well. Just make sure to download the 32-bit version of everything and use the appropriate paths to those versions instead.

mscharley avatar Mar 26 '18 20:03 mscharley

@mscharley U can use the free VirtualBox Windows from Microsoft. I'm using that to test.

Ok, I'll follow your guide, and test with MSYS2 packages (and compiling from source whenever things fail). Will report modifications/simplifications to your guide.

What do I do for --prefix if I'm using RubyInstaller2 (not DevKit)?

UPDATE: @mscharley I got the same errors as before. How do I actually tell rugged.so to use the libssh2 I just compiled?

jhannwong avatar Mar 27 '18 04:03 jhannwong