Compiling libssh2 on windows
Asked Answered
L

1

10

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....?

Livelihood answered 3/7, 2017 at 15:40 Comment(4)
I am almost sure that you did. But I need to ask. Did you follow the installation guide proposed in github??Haslett
@Haslett I know, but when cmake --build generates 2916 errors!Livelihood
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)?Haslett
@Haslett Ya, I think is that, I'm trying to use openssl, but I don't now how to do that.Livelihood
H
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.

Haslett answered 3/7, 2017 at 17:2 Comment(12)
Yes but what if you want to use openssl as crypto backendWarfield
You need to compile 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 libssh2Haslett
I have OpenSSL compiled but Cmake can't find itWarfield
@Warfield If cmake doesn't detect automatically the openssl required variables, you need to fulfill manually the cmake required variables (this variables). See this answer, maybe it could help you.Haslett
Thank you @HaslettWarfield
Thanks for this, nothing more painful than trying to get another persons library to compile in Windows 10Verbiage
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 OFFVerbiage
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.Argentina
If debugging is needed, add -DCMAKE_BUILD_TYPE=Debug to the command line.Ariosto
@Argentina 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.Ariosto
Doesn't seem to work anymore.. libssh2\dlltest2> cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./dll --build . CMake Error: Unknown argument --build CMake Error: Run 'cmake --help' for all supported options.Samuel
@Ionut-AlexandruBaltariu I found the same thing. cmake must have changed their command line options. I removed the --build . from the end and it worked. Tested with cmake 3.28.3. The OP references 3.9.0.Sapid

© 2022 - 2024 — McMap. All rights reserved.