2013-03-07 157 views
1

我已經按照here的教程來設置我的Eclipse安裝,並使用Boost和本教程底部的示例來測試編譯工作。我試圖用asio的插座,但在編譯時我收到如下:Boost C++ code not building,can someone help me with library linking?

**** 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

回答

1

你得到的錯誤確實是鏈接錯誤,因爲缺少庫(可能是你列出的)。

快速搜索導致這兩個SO條目:

注意,在eclipse/CDT的某些版本有一個在圖書館標籤符號&路徑配置窗口,但它似乎並沒有出現在所有版本中,所以你必須訴諸於第e鏈接器配置面板,如上面鏈接的答案中所述。

如果您從相同的站點瀏覽過前一個教程,您鏈接到您的問題(關於設置eclipse和cdt的問題),並設法編譯示例程序,那麼2個boost庫是唯一缺失的。否則,您可能需要添加其他幾個(錯誤消息中的某些缺失符號與winsock系統庫有關)。