zaphoyd / websocketpp

C++ websocket client/server library
http://www.zaphoyd.com/websocketpp
Other
7.01k stars 1.97k forks source link

Building a project in Visual Studio 2019? #992

Open StasToken opened 3 years ago

StasToken commented 3 years ago

Hi friends, interested in whether there is a step-by-step guide on how to build an example for Visual Studio 2019?

I tried to follow this manual - but nothing works at all...

malopezmx commented 3 years ago

Hi StasToken, I've been through the same nightmare. Even though the steps, once you know them, seem easy and logical, getting to them is not easy, at least it wasn't for me because there are many concepts involved and most of them were new for me. I needed to create a Websocket server to add functionality to a legacy C++ MFC app.

First, you need to install boost and openSSL: Boost from https://www.boost.org/users/history/version_1_76_0.html openSSL from https://github.com/openssl/openssl. And of course you need to git clone the websocketpp somewhere (let's assume you have it in F:\websocketpp).

Once that is done, you should go through the following steps:

  1. Create an empty VS2019 solution. I created mine in the "examples" folder of the websocketpp main folder (git clone).
  2. Manually add a new empty project named "EchoServer".
  3. Add to the "Source Files" filter in that project the files "echo_handler.hpp" and "echo_server.cpp" which are in folder "examples/echo_server".
  4. Assuming your main websocketpp folder is F:\websocketpp, then right-click on the project EchoServer in the Solution Explorer and select "Properties".
  5. Under Configuration Properties->General, make sure that "C++ Language Standard" is set to ISO C++17 Standard. It should also work with the default C++ 14, but just in case.
  6. Under C/C++->General->Additional Include Directories, manually add (for "All Configurations" and "All Platforms"): -F:\websocketpp (where subfolder websocketpp contains the websocketpp headers) -your boost root folder (for instance C:\boost\boost_1_76_0)
  7. Under C/C++->Code Generation, ensure the Runtime Library is multi-threaded (DLL or static depending on what you built for boost)
  8. Under Linker->General->Additional Library Directories, manually add: -your boost lib folder (for instance C:\boost\boost_1_76_0\stage_lib) -your openSSL lib folder (that depends on how and where you've arranged your openSSL. There could be separate folders for debug, release, x86 and x64 versions).
  9. Under Linker->Input->Additional Dependencies, manually add: libcrypto.lib;libssl.lib;libcrypto64MTd.lib;libssl64MTd.lib; (for 64-bit debug), or libcrypto.lib;libssl.lib;libcrypto64MT.lib;libssl64MT.lib; (for 64-bit release), or libcrypto.lib;libssl.lib;libcrypto32MTd.lib;libssl32MTd.lib; (for 32-bit debug), or libcrypto.lib;libssl.lib;libcrypto32MT.lib;libssl32MT.lib; (for 32-bit release), etc.

After all that is done, you should be able to build the EchoServer project with VS2019 as usual and run it normally. I use the Chrome extension WebSocket King Client, although probably any other websocket client will work.

  1. Repeat steps 1 to 9 for those examples in the "examples" folder that you would like to build, to have a project for each one.

I am right now trying to find out why the TLS projects(echo_server_both and echo_server_tls) always send an error "handle_transport_init received error: sslv3 alert certificate unknown". I have used the .pem files that come with the library, and also generated my own ones with openssl, but still no success (testing with Chrome additions WebSocket King Client and Simple WebSocket Client, both generate the same error). If you know or find how to solve this, I will appreciate. Update: Found the problem in the last paragraph: the library will not accept a self-signed certificate (the ones you can create directly in your own PC using OpenSSL or the Windows utilities). There is no way around it. You must have a valid, authority-validated and endorsed certificate. You can get such certificate from https://zerossl.com/. The site has detailed instructions on how to request, obtain and install a certificate.

frankhale commented 3 years ago

You might find it easier to use vcpkg than doing manual setup of libraries in Visual Studio.

https://vcpkg.io/en/index.html

malopezmx commented 3 years ago

Thank you Frank. I have vcpkg and have used it, but to be honest, something I don't like is what I feel like a lack of transparency... yes it works but by "magic". It's easier to use than doing things by hand, but I am not 100% sure what and where it installs things or where it gets them from, and I feel it could be a nightmare to fully understand the changes it makes to the computer, or to transport the development environment to another PC. Probably because I don't know much about it, or I've been for too long doing things the old way... but for instance right now, if you install boost with vcpkg, you get version 1.75, however, the latest version of boost is 1.76. I don't know, it's like an itch... too OCD perhaps!