CPP-入Netlib使用HTTP客户端时身体提升的Mac OSX赛格故障 [英] cpp-Netlib with Boost Mac OSX seg fault when using HTTP Client body

查看:229
本文介绍了CPP-入Netlib使用HTTP客户端时身体提升的Mac OSX赛格故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始学习CPP-NETLIB需要升压并试图编译的CPP-NETLIB的例子之一,从有网站的 http://cpp-netlib.org/0.11.2/examples/http/http_client.html 。我从来没有使用升压,我想知道我应该怎么去搞清楚我的编译程序的时候什么联系呢?我使用自制作为我包管理器当前。我通过运行安装提振

I recently started learning cpp-netlib which requires Boost and am running into some issues when trying to compile one of the cpp-netlib examples from there site http://cpp-netlib.org/0.11.2/examples/http/http_client.html. I have never used Boost before and am wondering how I should go about figuring out what to link when compiling my program? I am using homebrew as my package manager currently. I installed boost by running

brew install boost --c++11

我然后通过运行安装CPP-NETLIB

I then installed cpp-netlib by running

brew install cpp-netlib

我复制并从网站和硬codeD粘贴code例如请求URI

I copied and pasted the code example from the site and hardcoded the request URI

#include <boost/network/protocol/http/client.hpp>
#include <iostream>
int main()
{
    using namespace boost::network;
    http::client client;
    http::client::request request("http://www.boost.org");
    request << header("Connection", "close");
    http::client::response response = client.get(request);
    std::cout << body(response) << std::endl;
    return 0;
}

在谷歌的时间与我的室友搜索,我们发现了什么刺激,我需要链接库,我们也发现,铛++是找到我的Mac电脑的老过时的OpenSSL是在pinstalled到操作系统$ P $,而不是新版本我已通过自制软件安装。有了这个新的知识,我们发现,使用这个命令的作品编译

After hours of Google searches with my roommate we found what boost libraries I needed to link, we also found that clang++ was finding my Macs old outdated openssl that is preinstalled in to the operating system and not the new version that I had installed through homebrew. With this new knowledge we found that compiling with this command works

clang++ -g -I /usr/local/Cellar/openssl/1.0.2e/include test.cpp -L /usr/local/Cellar/openssl/1.0.2e/lib -lboost_system-mt -lboost_thread-mt -lcppnetlib-client-connections -lcppnetlib-uri -lcppnetlib-server-parsers -lssl -lcrypto

运行程序时我现在得到一个分段错误。当我尝试运行LLDB调试我的程序LLDB与退出总线错误:10。
我发现,赛格故障发生在运行此行code时

I am now getting a segmentation fault when running the program. When I attempt to run lldb to debug my program lldb exits with a "bus error: 10". I found that the seg fault is occurring when running this line of code

std::cout << body(response) << std::endl;

当我跑Valgrind的,我得到以下输出

When I run valgrind I get the following output

==1123== Memcheck, a memory error detector
==1123== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==1123== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==1123== Command: ./a.out
==1123== 
--1123-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
--1123-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times)
--1123-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times)
--1123-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 8 times)
==1123== Thread 2:
==1123== Jump to the invalid address stated on the next line
==1123==    at 0x0: ???
==1123==    by 0x100016A5A: boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) (task_io_service.ipp:372)
==1123==    by 0x10001669A: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:149)
==1123==    by 0x10000FDD0: boost::asio::io_service::run() (io_service.ipp:59)
==1123==    by 0x1000196D1: boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator()(boost::asio::io_service*) const (in ./a.out)
==1123==    by 0x100019620: unsigned long boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0>(boost::_bi::type<unsigned long>, boost::_mfi::mf0<unsigned long, boost::asio::io_service>&, boost::_bi::list0&, long) (in ./a.out)
==1123==    by 0x10001959B: boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator()() (in ./a.out)
==1123==    by 0x10001874B: boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::run() (thread.hpp:116)
==1123==    by 0x1003ADFD5: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/Cellar/boost/1.59.0/lib/libboost_thread-mt.dylib)
==1123==    by 0x100B289B0: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==1123==    by 0x100B2892D: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==1123==    by 0x100B26384: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==1123==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1123== 
==1123== 
==1123== Process terminating with default action of signal 11 (SIGSEGV)
==1123==  Bad permissions for mapped region at address 0x0
==1123==    at 0x0: ???
==1123==    by 0x100016A5A: boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) (task_io_service.ipp:372)
==1123==    by 0x10001669A: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service.ipp:149)
==1123==    by 0x10000FDD0: boost::asio::io_service::run() (io_service.ipp:59)
==1123==    by 0x1000196D1: boost::_mfi::mf0<unsigned long, boost::asio::io_service>::operator()(boost::asio::io_service*) const (in ./a.out)
==1123==    by 0x100019620: unsigned long boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> >::operator()<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list0>(boost::_bi::type<unsigned long>, boost::_mfi::mf0<unsigned long, boost::asio::io_service>&, boost::_bi::list0&, long) (in ./a.out)
==1123==    by 0x10001959B: boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > >::operator()() (in ./a.out)
==1123==    by 0x10001874B: boost::detail::thread_data<boost::_bi::bind_t<unsigned long, boost::_mfi::mf0<unsigned long, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >::run() (thread.hpp:116)
==1123==    by 0x1003ADFD5: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/Cellar/boost/1.59.0/lib/libboost_thread-mt.dylib)
==1123==    by 0x100B289B0: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==1123==    by 0x100B2892D: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==1123==    by 0x100B26384: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==1123== 
==1123== HEAP SUMMARY:
==1123==     in use at exit: 150,091 bytes in 3,656 blocks
==1123==   total heap usage: 3,912 allocs, 256 frees, 194,518 bytes allocated
==1123== 
==1123== LEAK SUMMARY:
==1123==    definitely lost: 400 bytes in 4 blocks
==1123==    indirectly lost: 80,493 bytes in 2,673 blocks
==1123==      possibly lost: 0 bytes in 0 blocks
==1123==    still reachable: 47,160 bytes in 790 blocks
==1123==         suppressed: 22,038 bytes in 189 blocks
==1123== Rerun with --leak-check=full to see details of leaked memory
==1123== 
==1123== For counts of detected and suppressed errors, rerun with: -v
==1123== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Killed: 9

任何帮助很多AP preciated!

Any help is much appreciated!

推荐答案

我发现,摆脱了段错误的,我需要包括-std = C ++ 11使得命令编译

I found that to get rid of the segmentation fault I needed to include -std=c++11 making the command to compile

clang++ -std=c++11 -I /usr/local/Cellar/openssl/1.0.2e/include test.cpp -L /usr/local/Cellar/openssl/1.0.2e/lib -lboost_system -lboost_thread-mt -pthread -lcppnetlib-client-connections -lcppnetlib-uri -lcppnetlib-server-parsers -lssl -lcrypto

我也许应该创建一个make文件。

I should probably create a make file.

这篇关于CPP-入Netlib使用HTTP客户端时身体提升的Mac OSX赛格故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆