繁体   English   中英

如何在Windows上安装Boost

[英]How to install boost on windows

我正在使用Windows 8.1,Visual Studio社区2013。
我下载了Boost 1.59。
然后,我打开Developer Command Prompt for VS2013 ,运行bootstrap.bat,然后运行b2.exe。

所有.lib文件都放在./stage/lib/下。

我设置了c ++包含路径和链接器路径。 我成功构建了程序,并在调试模式下运行。
这是我收到的错误消息:

Unhandled exception at 0x77394598 in BoostStation.exe: Microsoft C++ exception: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> > at memory location 0x001BFD74.

这是断点:

throw enable_current_exception(enable_error_info(e)); // from throw_exception.hpp

有人知道如何解决问题吗?
另一个问题,此生成是否生成任何.dll文件?在哪里可以找到它们?

这是我的程序:
组播发送器

#include <boost/asio.hpp>
#include <boost/scoped_ptr.hpp>
#include <string>

class MulticastSender
{
public:
    MulticastSender(const boost::asio::ip::address& multicast_addr, const unsigned short multicast_port)
        : ep_(multicast_addr, multicast_port)
    {
        socket_.reset(new boost::asio::ip::udp::socket(svc_, ep_.protocol()));
    }

    ~MulticastSender()
    {
        socket_.reset(NULL);
    }

public:
    void send_data(const std::string& msg)
    {
        socket_->send_to(boost::asio::buffer(msg), ep_);
    }

private:
    boost::asio::ip::udp::endpoint                  ep_;
    boost::scoped_ptr<boost::asio::ip::udp::socket> socket_;
    boost::asio::io_service                         svc_;
};

main.cpp

#include "stdafx.h"
#include "MulticastSender.h"


int _tmain(int argc, _TCHAR* argv[])
{
    boost::asio::ip::address multiCastGroup;
    multiCastGroup.from_string("192.168.32.1");
    MulticastSender outDoor(multiCastGroup, 6000);

    while (true)
    {
        outDoor.send_data("Hello");
        Sleep(1000);
    }

    return 0;
}

您可以进行boost安装,因为显然您可以编译并链接一个引发boost::exception

通过将代码包装在try / catch块中来捕获异常,然后打印出消息。 我相应地更改了您的main功能:

#include "stdafx.h"
#include "MulticastSender.h"
#include "boost/exception.hpp"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        boost::asio::ip::address multiCastGroup;
        multiCastGroup.from_string("192.168.32.1");
        MulticastSender outDoor(multiCastGroup, 6000);

        while (true)
        {
            outDoor.send_data("Hello");
            Sleep(1000);
        }
    }
    catch (const std::exception& e)
    {
        std::cout << boost::diagnostic_information(e) << std::endl;
    }
    return 0;
}

这将捕获boost引发的异常并在程序退出之前打印其消息。

您还应该阅读一般的例外情况: http : //www.cplusplus.com/doc/tutorial/exceptions/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM