0

我正在尝试使用 boost.asio 来实现多播发送者。我有一个我的线程实现,我只需要我的 boost.asio 来管理套接字。

我查看了 boost 网站上的示例,但我不明白,我不编译。我在哪里可以找到我需要的东西?

编译错误是:(我试过这个例子: http: //www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/multicast/sender.cpp

错误 3 错误 C2653: 'asio' : 不是类或命名空间名称 c:\Documents and Settings\GG\Desktop\sender.cpp 2

错误 4 错误 C2653: 'asio' : 不是类或命名空间名称 c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 5 错误 C2143:语法错误:在 '&' 之前缺少 ')' c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 6 错误 C2143:语法错误:缺少 ';' 在'&'之前 c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 7 错误 C2460: 'sender::io_service' : 使用 'sender',正在定义 c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 8 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 9 错误 C2653: 'asio' : 不是类或命名空间名称 c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 10 错误 C2143:语法错误:缺少 ';' 在'&'之前 c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 11 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 13 错误 C2059:语法错误:')' c:\Documents and Settings\GG\Desktop\sender.cpp 24

错误 14 错误 C2065:'multicast_address':未声明的标识符 c:\Documents and Settings\GG\Desktop\sender.cpp 26

错误 15 error C3861: 'endpoint_': identifier not found c:\Documents and Settings\GG\Desktop\sender.cpp 26

错误 16 错误 C2531: 'sender::multicast_address' : 引用位字段非法 c:\Documents and Settings\GG\Desktop\sender.cpp 26

错误 17 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int c:\Documents and Settings\GG\Desktop\sender.cpp 26

错误 18 错误 C2327: 'sender::io_service' : 不是类型名称、静态或枚举器 c:\Documents and Settings\GG\Desktop\sender.cpp 27

错误 19 错误 C2061:语法错误:标识符 'io_service' c:\Documents and Settings\GG\Desktop\sender.cpp 27

错误 20 错误 C2059:语法错误:')' c:\Documents and Settings\GG\Desktop\sender.cpp 27

错误 21 错误 C2061:语法错误:标识符 'timer_' c:\Documents and Settings\GG\Desktop\sender.cpp 28

错误 22 错误 C2143:语法错误:在 '{' c:\Documents and Settings\GG\Desktop\sender.cpp 30 之前缺少 ')'

错误 23 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持默认整数 c:\Documents and Settings\GG\Desktop\sender.cpp 30

错误 24 错误 C2143:语法错误:缺少 ';' 在'{'之前 c:\Documents and Settings\GG\Desktop\sender.cpp 39

错误 25 错误 C2334: '{' 前面的意外令牌;跳过明显的函数体 c:\Documents and Settings\GG\Desktop\sender.cpp 39

错误 26 致命错误 C1004: 发现意外的文件结尾 c:\Documents and Settings\GG\Desktop\sender.cpp 100

4

1 回答 1

0

假设您正确安装了 boost,您选择编译的示例应该可以干净地构建。我不知道你的开发环境是如何设置的。在我的系统上,我安装了 boost,/opt/local因此标题位于/opt/local/include其中,要链接的库位于/opt/local/lib. 我的编译和链接行看起来像

stackoverflow samm$ g++ sender.cpp  -I /opt/local/include/ -L/opt/local/lib -lboost_system -Wl,-rpath,/opt/local/lib

您看到的第一个错误

错误 3 错误 C2653: 'asio' : 不是类或命名空间名称 c:\Documents and Settings\GG\Desktop\sender.cpp 2

看起来你忘记了#include <boost/asio.hpp>某个地方。但是我远不是Windows开发专家,所以也许有更多知识的人会回答。

于 2011-04-19T20:30:05.867 回答