在尝试编译代码(使用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_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无效。
请帮助我理解如何解决这个问题。
谢谢!
发布于 2022-07-18 07:32:41
我也面临着同样的问题。这是我的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;
}
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不支持从流中提取‘)。
https://stackoverflow.com/questions/72265642
复制相似问题