好的,过去一周我一直在尝试在 Google 上找到解决方案并搜索多个编码站点,包括以下链接:
这就是我知道如何使用
-D_WIN32_WINNT=0x0601 -DWINVER=0x0601
在编译行中。
我正在使用带有 Dev-C++ 的 Windows 7(64 位),每次编译 Boost:Asio 示例时都会出现以下错误:
Compiler: Default compiler
Building Makefile: "D:\Tutorials\Asio\Makefile.win"
Executing make...
make.exe -f "D:\Tutorials\Asio\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"D:/Programs/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"D:/Programs/Dev-Cpp/include/c++/3.4.2/backward" -I"D:/Programs/Dev-Cpp/include/c++/3.4.2/mingw32" -I"D:/Programs/Dev-Cpp/include/c++/3.4.2" -I"D:/Programs/Dev-Cpp/include" -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -lboost_system-mgw44-mt-1_49
In file included from D:/Programs/Dev-Cpp/include/boost/asio/detail/win_object_handle_service.hpp:180,
from D:/Programs/Dev-Cpp/include/boost/asio/windows/object_handle_service.hpp:24,
from D:/Programs/Dev-Cpp/include/boost/asio/windows/basic_object_handle.hpp:27,
from D:/Programs/Dev-Cpp/include/boost/asio.hpp:99,
from main.cpp:3:
D:/Programs/Dev-Cpp/include/boost/asio/detail/impl/win_object_handle_service.ipp: In member function `void boost::asio::detail::win_object_handle_service::register_wait_callback(boost::asio::detail::win_object_handle_service::implementation_type&, boost::asio::detail::scoped_lock<boost::asio::detail::win_mutex>&)':
D:/Programs/Dev-Cpp/include/boost/asio/detail/impl/win_object_handle_service.ipp:376: error: `RegisterWaitForSingleObject' undeclared (first use this function)
D:/Programs/Dev-Cpp/include/boost/asio/detail/impl/win_object_handle_service.ipp:376: error: (Each undeclared identifier is reported only once for each function it appears in.)
D:/Programs/Dev-Cpp/include/boost/asio/detail/impl/win_object_handle_service.ipp: In static member function `static void boost::asio::detail::win_object_handle_service::wait_callback(void*, BOOLEAN)':
D:/Programs/Dev-Cpp/include/boost/asio/detail/impl/win_object_handle_service.ipp:418: error: `RegisterWaitForSingleObject' undeclared (first use this function)
make.exe: *** [main.o] Error 1
Execution terminated
我的代码如下:
#define _WIN32_WINNT 0x0601
#define __USE_W32_SOCKETS
#include <boost/asio.hpp>
#include <iostream>
int main()
{
// Cre'ation du service principal et du re'solveur.
boost::asio::io_service ios;
boost::asio::ip::tcp::resolver resolver(ios); // (1)
// Parame`trage du resolver sur Developpez.com
boost::asio::ip::tcp::resolver::query query("www.developpez.com", "80"); // (2)
// On re'cupe`re une "liste" d'ite'rateur
boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query); // (3)
boost::asio::ip::tcp::resolver::iterator end; //Marqueur de fin
while (iter != end) // On ite`re le long des endpoints
{
boost::asio::ip::tcp::endpoint endpoint = *iter++;
std::cout << endpoint << std::endl; // on affiche (4)
}
return 0;
}
考虑到代码本身没有给出错误,这没关系。这只是我一直在使用的五个教程之一,这些教程给了我与 Boost:Asio 相同的、确切的错误。
已经给出了一些建议,例如在链接器中使用“-lwsock32”,在编译器中也使用“-lboost_system-mgw44-mt-1_49”,但这并没有做任何事情。按照建议添加“-D_WIN32_WINNT=0x0601 -DWINVER=0x0601”消除了一些错误,但这就是我所得到的。
我非常认真地在我的程序中实施 Boost:Asio,所以如果我能得到一个工作示例,我可以从各种资源中更好地理解它并按预期使用它。因此,请不要给我任何关于“把它留给专业人士”或“学习编程”的信息,因为我在其他论坛上一次又一次地看到有人就这个错误寻求帮助。即使我知道如何编程,但在使用我不熟悉的库时仍然会遇到这样的错误。
提前致谢!