簡體   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