Use boost::asio without linking to OpenSSL - c++

I'm working on a project that uses boost::asio. By default it links with OpenSSL libraries, however no SSL features are used. I need to get rid of OpenSSL dependencies, is there a way to do it? Thanks

Your question doesn't really make sense as the OpenSSL part of boost asio is optional. i.e. it only links in openssl when you use it.
Also by default boost asio is header only. So you must have gone out of your way to compile the library version WITH openssl included.
You can read about it here.
If you want to only include openssl when you use it, then I would just use the default header only version and you will only get what you use and nothing more.

Compile boost yourself and remove the OpenSSL bits first. Would be "a way to do it".

Related

Problem compiling WebRTC and boost::uuid due to X509 redefinition problem. Where should I create issue?

I'm experimenting with WebRTC and stumbled upon annoying problem. While using both:
BoringSSL(which is third_party for WebRTC) and boost::uuid I cannot compile my solution due to X509 redefinition problem.
Problem:
BoringSSL define X509 by its own so when I link wincrypt.h via boost::uuid which defines it by itself, redefinition problem occurs. This problem will occur every time you will try to use wincrypt.h or any other third_party that depends on it along with WebRTC.
Solution:
I may use something other than boost::uuid
I can add in BoringSSL file base.h, #undef preproccessor macros:
#ifdef CRYPT
#undef X509_NAME
#undef X509_CERT_PAIR
#undef X509_EXTENSIONS
#endif
That way you can use in your project's CMake
add_definitions(-DCRYPT)
and problem will be instantly solved. Flag name is irrelevant, just example.
My second solution is preferable and I would like it to be included into further versions of BoringSSL for WebRTC. On BoringSSL website there is an information which state:
Programs ship their own copies of BoringSSL when they use it and we update everything as needed when deciding to make API changes. This allows us to mostly avoid compromises in the name of compatibility. It works for us, but it may not work for you.
My questions:
Does that quote means that with WebRTC somehow unique version of BoringSSL is shipped?
If so, where should I direct my issue? I would like to contribute so it would help someone else in the future but I am not sure where, to WebRTC repo? To BoringSSL?
Thanks in advance for clearing it out for me.
Boost.Asio relies on OpenSSL library. It should not be a surprise that OpenSSL and BoringSSL are not compatible. Putting the #ifdef CRYPT plaster that you propose may actually put much more serious incompatibility issues under the carpet. I believe that the right way would be to compile WebRTC with OpenSSL, or use BoringSSL for all your project, just like nghttp2 did it.

Create a fully static Libcurl library

First I'll explain the big picture :
I am creating an application where I separated most of the features in different libraries. One of them contains some classes that use curl. I actually use Ubuntu 64 bit to develop and test it, but my production environment is a NAS with an ARM processor. I intend to, later, also make it for windows.
Where I am now :
My application is running on linux and the ARM-based NAS. However, I don't link with curl, I use curl from command-line internally to do what I need. This has some drawbacks :
As a programmer, I consider it an ugly practice. I should link to libcurl, this is the normal and clean way of using features from other software components.
This implies that curl executable is installed on the target. Not only I don't want to rely on this but also after a system upgrade on the NAS, I found out that I can't rely anymore on this.
What I want
As I intended anyway to use curl as a library, I first tried to do it the "soft way" : dynamic linking. Although it worked on my development environment, it didn't work on the production one because I found out that the curl library installed there doesn't work as expected.
So my next try was using libcurl as a static library. I also considered it to be the best future-proof option for me as it would make sure that, either on the NAS or on any other system, the library I will be using will always be the same.
The problems I've solved so far
Including a static library in another static library
This is already well documented in other answers here in StackOverflow : How to merge two "ar" static libraries into one
I did this to create a combined library of my own one and libcurl and as far as I've checked, it worked.
Building libcurl statically from source
There also are other answers that cover this topic, and I managed to create a libcurl.a that has libcurl features only.
The problems I am still trying to solve
Building libcurl statically with all its dependencies
There are some information regarding this, for example here. I did what was suggested, calling the configure script with --disable-shared and --enable-static. I also did the "rm src/curl" before make and called make with LDFLAGS=-all-static, but the resulting libcurl still missed its dependencies (openssl, pthreads, zlib...).
If I could solve this problem, it would answer my question. But not having succesfully done that, I tried another approach :
Manually merging all libcurl dependencies in a final lib
As I did for merging my library with libcurl into a new library, I also tried do add to it curl dependencies : zlib and openssl. So I compiled both from source to create static libraries and included them in the merge. I was not able to fully check the result as it seems that another one is missing : pthread. And I was not able to find pthread for downloading - compiling - static linking.
Looking at the big picture, my main problem is : how to I include curl in my final application so that there is no external dependency to it?
I think that if either of my two remaining problems would be solved, I would be solving my main problem. But if it is not the case, I also would be glad to hear from someone who knows a better way of solving this, or ideally already solved a similar issue.

How to know which version of openssl boost ssl is using

I have some questions about boost openssl updation
How can I find out which version of openssl boost ssl is using?
Do we need to recompile the C++ boost application after updating openssl or will updating openssl suffice?
Boost will use the openssl version provided by your system (or explicitly specified during compilation/linkage, check your build script)
It depends on your linkage type, if you link statically against OpenSSL, you will need to recompile. If you are linking dynamically, then updating the DLL/shared object will be enough (unless you linked against a specific version)

Is there any way to extract Boost Regex so I can package it with my project?

I'm working on a project written in C++ that uses the Boost Regex library to do some parsing. My problem is, I need to run the program on a remote machine that doesn't have the boost library installed. I also don't have admin access to this computer so I can't just install it myself.
Is there any way to separate out just the Boost Regex library so that I can put it in the same directory as my other code? I tried doing this already by downloading the boost library and separating out all of the unneeded headers and such. I managed to get it to a point where it calmost compiled but it failed at the linking stage.
Is there anything I can do to fix this or will I be forced to rewrite the parsing code?
You can use the Boost.BCP tool to extract a subset of Boost.
include the static library libboost_regex-gcc-1_35.a your list of object files to compile.
1_35 is an older version number on my linux box, you may have a newer library

Boost.Asio as header-only

I want to use ASIO library from Boost in my project. Its doc say it can be header-only if regex is not used and SSL not used. However, running bcp for asio pulls a very many libraies some of which are with sources so need compiling, bjam etc.
Can I somehow use ASIO in project as only headers, without libs/source? I only need ASIO, not other part of Boost.
EDIT: ASIO want Boost.System which has a lib to link - can this dependency not be so that I can use header only ASIO?
AFAIK you can get the non-boost version of asio from http://think-async.com/Asio/AsioAndBoostAsio
"— Boost.Asio uses the Boost.System library to provide support for error codes ( boost::system::error_code and boost::system::system_error). Asio includes these under its own namespace ( asio::error_code and asio::system_error). The Boost.System version of these classes currently supports better extensibility for user-defined error codes.
— Asio is header-file-only and for most uses does not require linking against any Boost library. Boost.Asio always requires that you link against the Boost.System library, and also against Boost.Thread if you want to launch threads using boost::thread."
UPDATE – 07/25/2019:
As noted in the comment below by #OleThomsenBuus (thank you!), from Boost 1.69 onward, Boost.System is now header-only, so there's no need to jump through all these hoops to eliminate the need to link with it.
ORIGINAL ANSWER:
The accepted answer is 100% effective and recommended, but another option—if you really want/need to use Boost Asio—is to try compiling your application with -DBOOST_ERROR_CODE_HEADER_ONLY. Use of this macro (documented here) should get around the need to link with Boost.System. However, it's worth reading the caveats pointed out in this answer. In particular, you may need to create a 'dummy' CPP file containing:
#define BOOST_ERROR_CODE_HEADER_ONLY
#include <boost/system/error_code.hpp>
and disable optimization for that file only. (Personally, I didn't need to do this, but YMMV...)
I think bcp pulls the regex library because it can be used (and on Windows machines it is used by default). I expect that you can delete the regex library source files no problem. Make sure you add the correct compiler flags if you are compiler on windows
(-DBOOST_DATE_TIME_NO_LIB and -DBOOST_REGEX_NO_LIB)
The details are from this page (which by the sounds of it you have already found).
I'm not sure how smart bcp is - I'm don't think you can pass it the defines given above that prevent it following the mscv route.