c++ - Boost C++ 代码未构建,有人可以帮助我进行库链接吗?

标签 c++ eclipse boost libraries

我已按照 here 中的教程进行操作使用 Boost 和教程底部的示例设置我的 Eclipse 安装以测试编译工作。我正在尝试将 asio 用于套接字,但在编译时收到以下信息:

**** Build of configuration Debug for project Client ****

**** Internal Builder is used for build               ****
g++ -IC:\MinGW\Boost\include\boost-1_53 -O0 -g3 -Wall -c -fmessage-length=0 -o src\Client.o ..\src\Client.cpp
g++ -LC:\MinGW\Boost\lib -o Client.exe src\Client.o
src\Client.o: In function `__static_initialization_and_destruction_0':
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
src\Client.o: In function `boost::system::error_code::error_code()':
C:/MinGW/Boost/include/boost-1_53/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
src\Client.o: In function `boost::asio::error::get_system_category()':
C:/MinGW/Boost/include/boost-1_53/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
src\Client.o: In function `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&, unsigned char, unsigned char)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `__imp_WSAStartup'
src\Client.o: In function `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/winsock_init.ipp:48: undefined reference to `__imp_WSACleanup'
src\Client.o: In function `boost::asio::detail::socket_ops::clear_last_error()':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:51: undefined reference to `__imp_WSASetLastError'
src\Client.o: In function `boost::asio::detail::socket_ops::close(unsigned long long, unsigned char&, bool, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:297: undefined reference to `__imp_closesocket'
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:314: undefined reference to `__imp_ioctlsocket'
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:329: undefined reference to `__imp_closesocket'
src\Client.o: In function `boost::asio::detail::socket_ops::recv(unsigned long long, _WSABUF*, unsigned long long, int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:683: undefined reference to `__imp_WSARecv'
src\Client.o: In function `boost::asio::detail::socket_ops::send(unsigned long long, _WSABUF const*, unsigned long long, int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1066: undefined reference to `__imp_WSASend'
src\Client.o: In function `boost::asio::detail::socket_ops::socket(int, int, int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1294: undefined reference to `__imp_WSASocketA'
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1305: undefined reference to `__imp_setsockopt'
src\Client.o: In function `boost::asio::detail::socket_ops::poll_read(unsigned long long, unsigned char, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1716: undefined reference to `__imp_select'
src\Client.o: In function `boost::asio::detail::socket_ops::poll_connect(unsigned long long, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1797: undefined reference to `__imp_select'
src\Client.o: In function `boost::asio::detail::socket_ops::translate_addrinfo_error(int)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:2869: undefined reference to `__imp_WSAGetLastError'
src\Client.o: In function `boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:2887: undefined reference to `__imp_getaddrinfo'
src\Client.o: In function `boost::asio::detail::socket_ops::freeaddrinfo(addrinfo*)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:2930: undefined reference to `__imp_freeaddrinfo'
src\Client.o: In function `unsigned long long boost::asio::detail::socket_ops::error_wrapper<unsigned long long>(unsigned long long, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:62: undefined reference to `__imp_WSAGetLastError'
src\Client.o: In function `int boost::asio::detail::socket_ops::error_wrapper<int>(int, boost::system::error_code&)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:62: undefined reference to `__imp_WSAGetLastError'
src\Client.o: In function `int boost::asio::detail::socket_ops::call_connect<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, sockaddr const*, unsigned long long)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:452: undefined reference to `__imp_connect'
src\Client.o: In function `int boost::asio::detail::socket_ops::call_setsockopt<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, int, int, void const*, unsigned long long)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1340: undefined reference to `__imp_setsockopt'
src\Client.o: In function `int boost::asio::detail::socket_ops::call_getsockopt<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, int, int, void*, unsigned long long*)':
C:/MinGW/Boost/include/boost-1_53/boost/asio/detail/impl/socket_ops.ipp:1426: undefined reference to `__imp_getsockopt'
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 4033  ms.  

我假设我在链接库时哪里出错了。有人可以解释一下该教程的作者的意思吗

Under libraries, add the specific boost libraries you need. 
For example I have added:

boost_thread-mgw47-mt-d-1_52
boost_system-mgw47-mt-d-1_52

请解释(详细)如何在 Eclipse 中执行此操作(对于调试和发布)?谢谢。

哦,如果你想要代码,它只是找到的代码 here .

最佳答案

您得到的错误确实是链接错误,因为缺少库(可能是您列出的库)。

快速搜索找到了这两个 SO 条目:

请注意,在某些版本的 eclipse/CDT 中,符号和路径配置窗口中有一个库选项卡,但它似乎并不存在于所有版本中,因此您必须求助于链接器配置面板,如上面链接的答案。

如果您在问题中链接的同一站点上浏览了上一个教程(关于设置 eclipse 和 cdt 的教程),并设法编译了示例程序,那么 2 个 boost 库是唯一缺少的。否则,您可能需要添加其他一些符号(错误消息中缺少的一些符号与 winsock 系统库有关)。

关于c++ - Boost C++ 代码未构建,有人可以帮助我进行库链接吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15283715/

相关文章:

c++ - 从程序集引导加载程序调用 C++

c++ - 与 VS2013 相比,gcc 4.7.2 中的 std::map 实现效率非常低?

c++ - 使用 DOS 框运行 C++ 程序时出现问题?

支持 XML Schema 1.1 的 XML 编辑器

c++ - Boost.Filesystem 崩溃

c++ - 命名空间和运算符解析

eclipse - 在 goclipse 中重命名包会导致问题

java - 无法使用 Eclipse 更改 jFrame 图标/加载 .jar 的资源

c++ - 在没有 chrono 的 Windows 上使用 C++ 获取以纳秒为单位的时间

c++ - g++、clang++、使用 libboost 的编译花絮——当 g++7 成功时,g++8 编译失败;