[英]How to install boost on windows
I am using Windows 8.1, visual studio community 2013. 我正在使用Windows 8.1,Visual Studio社区2013。
I downloaded boost 1.59. 我下载了Boost 1.59。
I then open Developer Command Prompt for VS2013
, run bootstrap.bat, then run b2.exe. 然后,我打开Developer Command Prompt for VS2013
,运行bootstrap.bat,然后运行b2.exe。
All .lib files are placed under ./stage/lib/
. 所有.lib文件都放在./stage/lib/
下。
I set the c++ include path, and linker path. 我设置了c ++包含路径和链接器路径。 I built my program successfully and run under debug mode. 我成功构建了程序,并在调试模式下运行。
Here is the error message I get: 这是我收到的错误消息:
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.
Here is the break point: 这是断点:
throw enable_current_exception(enable_error_info(e)); // from throw_exception.hpp
Anyone knows how to solve the problem? 有人知道如何解决问题吗?
Another question, Are there any .dll files generated by this build and Where can I find them? 另一个问题,此生成是否生成任何.dll文件?在哪里可以找到它们?
Here is my program: 这是我的程序:
MulticastSender.h 组播发送器
#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 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;
}
Your boost installation is ok, because obviously you're able to compile and link a program that throws a boost::exception
. 您可以进行boost安装,因为显然您可以编译并链接一个引发boost::exception
。
Catch the exception by wrapping your code in a try
/ catch
block, then print out the message. 通过将代码包装在try
/ catch
块中来捕获异常,然后打印出消息。 I changed your main
-function accordingly: 我相应地更改了您的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;
}
This will catch the exception that is thrown by boost and print its message before the program exits. 这将捕获boost引发的异常并在程序退出之前打印其消息。
You should also read up on exceptions in general: http://www.cplusplus.com/doc/tutorial/exceptions/ 您还应该阅读一般的例外情况: http : //www.cplusplus.com/doc/tutorial/exceptions/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.