Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asio dependency on OpenSSL

While implementing code for SSL Handshake using Asio, the project does not build and throws error

C:\Eclipse\Boost\boost_1_62_0/boost/asio/ssl/detail/openssl_types.hpp:19:26: fatal error: openssl/conf.h: No such file or directory

So does it mean that for SSL using Asio we need to install OpenSSL ?

Well that's not the point i wanted to raise. The question is, is there any other alternate to use Asio SSL without asking client to install OpenSSL or in other words how can I statically bind OpenSSL with my application in a single executable?

like image 260
CocoCrisp Avatar asked Jan 05 '23 06:01

CocoCrisp


2 Answers

boost::asio uses OpenSSLfor SSL sockets: if you have:

#include <boost/asio/ssl.hpp>

in your code, then you'll need to build with OpenSSL as well as boost.

To build with OpenSSL:

  • define the macro BOOST_NETWORK_ENABLE_HTTPS at project level;
  • add the OpenSSL include directory to your include path;
  • add the OpenSSL library directory to your library path, e.g. -L$${OPENSSL_ROOT}/lib;
  • add the appropriate crypto libraries for your compiler, e.g.:

Windows, Visual Studio:

LIBS += -llibeay32
LIBS += -llibssleay32

Windows, MinGW:

LIBS += -lssl
LIBS += -lcrypto

Linux, GCC:

LIBS += -lssl
LIBS += -lcrypto
LIBS += -ldl

Note: you may have link issues with library order. I recommend including the OpenSSL libraries after the boost libraries; BTW boost::asio requires libboost_system.

like image 106
kenba Avatar answered Jan 11 '23 15:01

kenba


can I statically bind OpenSSL with my application in a single executable?

Yes. You can build openssl with the no-shared option and it will only build a static library:

https://wiki.openssl.org/index.php/Compilation_and_Installation

and then just put the static archive on your link command line and it will be statically linked - but the people you distribute it to do not.

However, for you to link the program you have to have the header files and static library available to your compiler/linker.

like image 37
xaxxon Avatar answered Jan 11 '23 14:01

xaxxon