Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

following boost::asio tutorial getting error with their code

I am a newbie to c++ and even newer to boost. After just installing and linking up boost to work in Code::Blocks I ran an example code and it seemed to work just fine.

I began going through the boost::asio tutorial. I literally tried copy and pasting their code, build and run it, and still get errors...

D:\Downloads\boost_1_55_0\boost\asio\detail\config.hpp|486|warning: #warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. [-Wcpp]|
D:\Downloads\boost_1_55_0\boost\asio\detail\config.hpp|487|warning: #warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line. [-Wcpp]|
D:\Downloads\boost_1_55_0\boost\asio\detail\config.hpp|488|warning: #warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target). [-Wcpp]|
obj\Debug\main.o||In function `_static_initialization_and_destruction_0':|
D:\Downloads\boost_1_55_0\boost\system\error_code.hpp|222|undefined reference to `boost::system::generic_category()'|
D:\Downloads\boost_1_55_0\boost\system\error_code.hpp|223|undefined reference to `boost::system::generic_category()'|
D:\Downloads\boost_1_55_0\boost\system\error_code.hpp|224|undefined reference to `boost::system::system_category()'|
obj\Debug\main.o||In function `ZN5boost6system10error_codeC1Ev':|
D:\Downloads\boost_1_55_0\boost\system\error_code.hpp|323|undefined reference to `boost::system::system_category()'|
obj\Debug\main.o||In function `ZN5boost4asio5error19get_system_categoryEv':|
D:\Downloads\boost_1_55_0\boost\asio\error.hpp|224|undefined reference to `boost::system::system_category()'|
obj\Debug\main.o||In function `ZN5boost4asio6detail17winsock_init_base7startupERNS2_4dataEhh':|
D:\Downloads\boost_1_55_0\boost\asio\detail\impl\winsock_init.ipp|39|undefined reference to `WSAStartup@8'|
obj\Debug\main.o||In function `ZN5boost4asio6detail17winsock_init_base7cleanupERNS2_4dataE':|
D:\Downloads\boost_1_55_0\boost\asio\detail\impl\winsock_init.ipp|56|undefined reference to `WSACleanup@0'|
obj\Debug\main.o||In function `ZN5boost4asio6detail10socket_ops16clear_last_errorEv':|
D:\Downloads\boost_1_55_0\boost\asio\detail\impl\socket_ops.ipp|69|undefined reference to `WSASetLastError@4'|
obj\Debug\main.o||In function `ZN5boost4asio6detail10socket_ops6selectEiP6fd_setS4_S4_P7timevalRNS_6system10error_codeE':|
D:\Downloads\boost_1_55_0\boost\asio\detail\impl\socket_ops.ipp|1742|undefined reference to `select@20'|
obj\Debug\main.o||In function `ZN5boost4asio6detail10socket_ops13error_wrapperIiEET_S4_RNS_6system10error_codeE':|
D:\Downloads\boost_1_55_0\boost\asio\detail\impl\socket_ops.ipp|82|undefined reference to `WSAGetLastError@0'|
||=== Build finished: 10 errors, 3 warnings (0 minutes, 3 seconds) ===|

1 Answers

For Eclipse, add symbol: _WIN32_WINNT val: 0x0601 (or for your windows system: http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745%28v=vs.85%29.aspx) to resolve the primary issue in the first 3 lines you quoted. I don't use code blocks but I imagine the process is similar.

Also add BOOST_ROOT/stage/lib to library include path and include the specific boost_system-whatever library.

like image 192
Enigma Avatar answered Mar 28 '26 19:03

Enigma