【问题标题】:openssl/conf.h file not found error on MacOS在 MacOS 上未找到 openssl/conf.h 文件错误
【发布时间】:2022-07-18 15:32:41
【问题描述】:

尝试编译代码(使用 cmake)时,我不断收到此错误:

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

我尝试关注这些链接,但没有任何帮助: Fatal Error: 'openssl/conf.h' file not found'openssl/conf.h' file not found error on on MacOS Big Sur'openssl/conf.h' file not found error on MacOS Sierra

以下是我的 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)

我也尝试过设置 LDFLAGS 和 CPPFLAGS,但没有帮助。 还尝试重新安装 boost - 不起作用。

请帮助我了解如何解决此问题。

谢谢!

【问题讨论】:

    标签: macos c++11 boost cmake openssl


    【解决方案1】:

    我也面临同样的问题。这是我的 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
    )
    

    这里是 C++ 测试代码(Boost 教程代码):

    #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;
    }
    

    操作系统: macOS Monterey 12.4 XCODE: 13.4.1 构建工具:忍者 IDE: CLion 2022.1.3

    顺便说一句。根据https://github.com/microsoft/cpprestsdk 文档,cmake 配置对于 cpprestsdk 来说是极简的,但它在 mac 上不起作用(在 windows 上也是一个问题 - cpprestsdk 包 -> #include -> 构建错误 C2338 static_assert failed : '不支持从流中提取类型')。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 2020-01-04
      • 2013-04-19
      • 2020-04-11
      • 2017-06-28
      相关资源
      最近更新 更多