首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >openssl/conf.h .h文件在MacOS上未找到错误

openssl/conf.h .h文件在MacOS上未找到错误
EN

Stack Overflow用户
提问于 2022-05-16 21:07:23
回答 1查看 178关注 0票数 1

在尝试编译代码(使用cmake)时,我一直收到以下错误:

代码语言:javascript
运行
复制
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

以下是我的简历:

代码语言:javascript
运行
复制
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 -din无效。

请帮助我理解如何解决这个问题。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-07-18 07:32:41

我也面临着同样的问题。这是我的CMakeLists.txt:

代码语言:javascript
运行
复制
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教程代码):

代码语言:javascript
运行
复制
#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 构建工具: Ninja IDE: CLion 2022.1.3

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72265642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档