运行 Casablanca 程序失败,在 Mac OS 上找不到 'openssl/conf.h' 文件
Running Casablanca program fails with 'openssl/conf.h' file not found on Mac OS
我正在尝试设置一个 Http 客户端并使用显示的示例下载一些数据 here。
当我尝试 运行 程序时,它失败并提示 "conf.h" 未找到。
$g++ -std=c++11 BingSearch.cpp
In file included from BingSearch.cpp:1:
In file included from /usr/local/include/cpprest/http_client.h:53:
In file included from /usr/local/include/boost/asio/ssl.hpp:19:
In file included from /usr/local/include/boost/asio/ssl/context.hpp:27:
In file included from /usr/local/include/boost/asio/ssl/context_base.hpp:19:
/usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:20:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
^
1 error generated.
我查看了其他 SO 并设置了必要的路径变量。
$echo $LDFLAGS
-L/usr/local/opt/openssl/lib
$echo $CPPFLAGS
-I/usr/local/opt/openssl/include
$echo $PKG_CONFIG_PATH
/usr/local/opt/openssl/lib/pkgconfig
另外 conf.h 位于 openssl 目录中
openssl $find /usr/local/opt/openssl/ -name "conf.h"
/usr/local/opt/openssl//include/openssl/conf.h
编译以下文件还需要做些什么吗?它来自 here.
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main(int argc, char* argv[])
{
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
// Build request URI and start the request.
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception &e)
{
printf("Error exception:%s\n", e.what());
}
return 0;
}
我尝试了@jww 的建议如下。
g++ -std=c++11 BingSearch.cpp -lssl -lcrypto -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include
这解决了 'conf.h' 找不到文件的错误。
但它仍然失败并出现以下错误。
Undefined symbols for architecture x86_64:
"web::uri_builder::append_query(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
web::uri_builder& web::uri_builder::append_query<char [18]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [18], bool) in BingSearch-582644.o
我关注了 https://github.com/Microsoft/cpprestsdk/issues/264 并解决了问题。
我可以使用以下命令编译程序。
g++ -std=c++11 BingSearch.cpp -stdlib=libc++ -lcpprest -lssl -lcrypto -lboost_system -lboost_thread-mt -lboost_chrono-mt -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include
我的PATH变量设置如下。
$echo $PATH
/usr/local/opt/openssl/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
我正在尝试设置一个 Http 客户端并使用显示的示例下载一些数据 here。
当我尝试 运行 程序时,它失败并提示 "conf.h" 未找到。
$g++ -std=c++11 BingSearch.cpp
In file included from BingSearch.cpp:1:
In file included from /usr/local/include/cpprest/http_client.h:53:
In file included from /usr/local/include/boost/asio/ssl.hpp:19:
In file included from /usr/local/include/boost/asio/ssl/context.hpp:27:
In file included from /usr/local/include/boost/asio/ssl/context_base.hpp:19:
/usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:20:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
^
1 error generated.
我查看了其他 SO
$echo $LDFLAGS
-L/usr/local/opt/openssl/lib
$echo $CPPFLAGS
-I/usr/local/opt/openssl/include
$echo $PKG_CONFIG_PATH
/usr/local/opt/openssl/lib/pkgconfig
另外 conf.h 位于 openssl 目录中
openssl $find /usr/local/opt/openssl/ -name "conf.h"
/usr/local/opt/openssl//include/openssl/conf.h
编译以下文件还需要做些什么吗?它来自 here.
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main(int argc, char* argv[])
{
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
// Build request URI and start the request.
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception &e)
{
printf("Error exception:%s\n", e.what());
}
return 0;
}
我尝试了@jww 的建议如下。
g++ -std=c++11 BingSearch.cpp -lssl -lcrypto -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include
这解决了 'conf.h' 找不到文件的错误。
但它仍然失败并出现以下错误。
Undefined symbols for architecture x86_64:
"web::uri_builder::append_query(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
web::uri_builder& web::uri_builder::append_query<char [18]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [18], bool) in BingSearch-582644.o
我关注了 https://github.com/Microsoft/cpprestsdk/issues/264 并解决了问题。
我可以使用以下命令编译程序。
g++ -std=c++11 BingSearch.cpp -stdlib=libc++ -lcpprest -lssl -lcrypto -lboost_system -lboost_thread-mt -lboost_chrono-mt -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include
我的PATH变量设置如下。
$echo $PATH
/usr/local/opt/openssl/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin