7

Some one can help me to compile libssh2 on windows with Visual Studio 2017. The only things I found are too old and outdated.

I downloaded libssh2 from github and run cmake libssh2 and then cmake -P cmake_install.cmake but can't find INSTALL file "libssh2.lib".

And I'm stuck here!

******** Update 1 ***********

Crypto_backend is missing, I trying to compile with openssl and get a lot of unresolved symbols.

******** Update 2 ***********

Ok! I used the cmake-gui and get rid of the unresolved symbols but now I'm having issues with some header files. libssh2 var types are not defined. Some kind of include missing....?

Samega 7Cattac
  • 191
  • 2
  • 14
  • 1
    I am almost sure that you did. But I need to ask. Did you follow the installation guide proposed in [github](https://github.com/libssh2/libssh2/blob/master/docs/INSTALL_CMAKE)?? – JTejedor Jul 03 '17 at 15:47
  • 1
    @JTejedor I know, but when `cmake --build` generates 2916 errors! – Samega 7Cattac Jul 03 '17 at 15:55
  • Sorry, As I said, I am almost sure. Which cypto-backend library did you use to build? Did you see that you can choose a windows native library (WinCNG)? – JTejedor Jul 03 '17 at 16:16
  • @JTejedor Ya, I think is that, I'm trying to use openssl, but I don't now how to do that. – Samega 7Cattac Jul 03 '17 at 16:29

1 Answers1

22

I could compile libssh2 in a Windows 10 environment (I was intrigued).

Environment:

  • Windows 10 x64.
  • Visual Studio Community 2017 version 15.2 (26430.4) Release.
  • CMake version 3.9.0-rc5 ( I had to uninstall a previous version manually before install the last version because the installer has changed, as the cmake web suggests).
  • Git version 2.10.1.windows.1

If you request any other crypto backend libraries than WinCNG , I am afraid you need to compile previously that crypto backend library before any attempt to compile libssh2 and make sure CMake find automatically the crypto-backend-library (if not, check for requested cmake variables and fulfill manually).

Steps in cmd to compile libssh2 using WinCNG and dynamic library option:

cd where/you/like/to/install
git clone https://github.com/libssh2/libssh2.git
cd libssh2
mkdir dll <-- directory to install libssh2
cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./dll --build .
cmake --build . --target install

And et voilà, after less than a minute, libssh is created and installed in dll directory.

I hope that this miniguide could help you.

JTejedor
  • 965
  • 6
  • 22
  • Yes but what if you want to use openssl as crypto backend – simon-p-r Jul 04 '17 at 10:21
  • You need to compile [OpenSSL](https://github.com/openssl/openssl) previously as I say in the answer (I think openssl web does not have any link to download the binaries directly). And I think that the OpenSSL compilation process for windows is harder than libssh2 – JTejedor Jul 04 '17 at 10:29
  • I have OpenSSL compiled but Cmake can't find it – simon-p-r Jul 04 '17 at 21:52
  • @simon-p-r If cmake doesn't detect automatically the openssl required variables, you need to fulfill manually the cmake required variables ([this variables](https://cmake.org/cmake/help/v3.9/module/FindOpenSSL.html)). See this [answer](https://stackoverflow.com/questions/43662998/cmake-can-not-find-openssl-on-windows), maybe it could help you. – JTejedor Jul 05 '17 at 08:07
  • Thank you @JTejedor – simon-p-r Jul 05 '17 at 09:10
  • 3
    Thanks for this, nothing more painful than trying to get another persons library to compile in Windows 10 – jparanich Jun 26 '18 at 21:09
  • Just wanted to add for future users that "DBUILD_SHARED_LIBS=ON" will build a .lib that still required libssh2.dll. For a static library you need to set this to OFF – jparanich Jul 13 '18 at 16:43
  • 1
    Wow. That actually worked. Without any of the rediculous steps that other approaches have required. It.... just worked. Well, sort of. After running those commands, I noticed a new visual studio solution file had been generated in the repository root as "libssh2.sln". I opened that, built the solution, and all 42 projects successfully built. I'm not sure why, during the script run, it looked like some files weren't found, but it definitely worked, and everything built after the solution was generated and built. – Triynko Nov 20 '18 at 20:12
  • If debugging is needed, add -DCMAKE_BUILD_TYPE=Debug to the command line. – yamex5 Oct 20 '20 at 16:55
  • @Triynko I noticed that also. However, libssh2 is meant to be built for several platforms, and Windows does not require some of the files needed for linux and mac. Even though those files are conditionally compiled out, cmake is checking them, or so it appears. – yamex5 Oct 20 '20 at 16:57