Thursday, December 20, 2018

Compiling libssh in Visual Studio 2017

I've decided to do a small write up on compiling libssh with Visual Studio 2017. It took me a little bit to get it working and there are no walk-throughs or tutorials online as far as I can tell. I saw quite a few people asking on forums and email archives on how to do this. I am typically a Linux user, so I don't have too much experience compiling in VS/Windows. Hopefully this will help someone that was stuck like I was!

So first thing is download the version of libssh you need from . In my case I am using version 0.8.5.

You will also need to install Openssl. I used a precompiled binary from here: . Installation is straightforward. Also, zlib is optional while compiling libssh. I did not include it as I didn't need it. Cmake is also required if you do not have it installed already. 

Extract the tarball into whatever directory you want it in. In my case I extracted it into C:/libs/libssh-0.8.5 . Create an empty directory to generate the build files into. For the sake of simplicity I just chose C:/libs/libssh-0.8.5/output . 

When you open Cmake, set the source code location to C:/<path>/libssh-0.8.5/ and the output location to wherever you created your output directory. 

Now click "Configure". You will be asked to choose the version of Visual Studio you are using. 

Click finish. Cmake will do it's thing for a bit. If you did NOT install zlib like I did, you will get this error. I think this is where most people are getting stuck. In the forums I saw, people 

Just scroll through the entries in the list and uncheck "WITH_ZLIB". The only reason I compiled this without zlib was that I was just working on a small personal project and didn't see a reason to include it.

When Cmake is done, the contents of your output directory should be full of the appropriate directories, files, VC++ Projects and "libssh.sln". Open the solution in Visual Studio. It should include these projects:

Build it via Build->Build Solution or (Crtl+Shift+B). The resulting .dll, .exp and .lib files will be located in your output directory in C:/<output path>/src/release . 

In hindsight this was incredibly simple, so I'm not sure why I had trouble with it. I think the people in the forums/emails I saw were trying to generate the build files in the wrong directory with Cmake. I was having problems getting it to build in VS, but that was probably my lack of experience with it. Anyways, hope this helped someone!   

No comments:

Post a Comment