1

When trying to compile code (using cmake), I keep getting this error :

In file included from /usr/local/include/cpprest/http_client.h:68:
In file included from /usr/local/include/boost/asio/ssl.hpp:18:
In file included from /usr/local/include/boost/asio/ssl/context.hpp:23:
In file included from /usr/local/include/boost/asio/ssl/context_base.hpp:19:
/usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:23:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
         ^~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/httpclient.dir/http_client.cpp.o] Error 1
make[1]: *** [CMakeFiles/httpclient.dir/all] Error 2
make: *** [all] Error 2

I have tried to follow these links but nothing helps : Fatal Error: 'openssl/conf.h' file not found and 'openssl/conf.h' file not found error on on MacOS Big Sur and 'openssl/conf.h' file not found error on MacOS Sierra

Following is my cmake :

cmake_minimum_required(VERSION 3.9)

find_package(cpprestsdk REQUIRED)

set (CMAKE_CXX_STANDARD 11)

add_executable(httpclient http_client.cpp)

set(OPENSSL_ROOT_DIR /usr/local/opt/openssl@3)
#set(OPENSSL_LIBRARIES /usr/local/opt/openssl@3/lib)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl@3/*)
set(OPENSSL_LIBRARIES /usr/local/opt/openssl@3/lib)
include(FindOpenSSL)

target_include_directories(httpclient INTERFACE ${OPENSSL_ROOT_DIR}/include)

target_link_libraries(httpclient PRIVATE cpprestsdk::cpprest
                                         openssl)

I have also tried setting LDFLAGS and CPPFLAGS, it din't help. Also tried re-installing boost - din't work.

Please help me understand how to resolve this.

Thanks!

2 Answers2

0

I'm facing the same problem. Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.22)
project(Test)

set(CMAKE_CXX_STANDARD 14)

set(OPENSSL_ROOT_DIR /usr/local/opt/openssl) # it points to openssl@3

find_package(Boost COMPONENTS system filesystem REQUIRED)

find_package(cpprestsdk REQUIRED)

add_executable(Test main.cpp)
target_link_libraries(
    Test
        PRIVATE Boost::system
        PRIVATE Boost::filesystem
)

Here is C++ test code (the Boost tutorial code):

#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <cpprest/http_msg.h> // the code can be compiled with this "include"
// #include <cpprest/http_client.h> // compilation with this "include" ends with the same openssl error

using boost::asio::ip::tcp;

std::string make_daytime_string()
{
    using namespace std; // For time_t, time and ctime;
    time_t now = time(0);
    return ctime(&now);
}

int main() {
    std::cout << "Ahoj" << std::endl;
    try
    {
        boost::asio::io_context io_context;

        tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 13));

        for (;;)
        {
            tcp::socket socket(io_context);
            acceptor.accept(socket);

            std::string message = make_daytime_string();

            boost::system::error_code ignored_error;
            boost::asio::write(socket, boost::asio::buffer(message), ignored_error);
        }
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}

OS: macOS Monterey 12.4 XCODE: 13.4.1 Build tool: Ninja IDE: CLion 2022.1.3

btw. According to https://github.com/microsoft/cpprestsdk documentation, the cmake configuration is minimalistic for cpprestsdk but it does not work on mac (on windows is a problem as well - cpprestsdk package -> #include <cpprest/http_listener.h> -> build error C2338 static_assert failed: 'type is not supported for extraction from a stream').

Venda
  • 1
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32271609) – The Dreams Wind Jul 21 '22 at 11:41
0

I had this exact issue. The problem was forgetting to link against the IMPORTED OpenSSL target, which is made available via find_package(OpenSSL).

In CMakeLists.txt, add the following:

target_link_libraries(httpclient PRIVATE OpenSSL::SSL)
caszi
  • 135
  • 9