How to fix undefined reference to `__imp_WSACleanup' (Boost.Asio) in CLion

被刻印的时光 ゝ 提交于 2019-12-12 18:18:48

问题


My C++ project includes Boost and WebSocket++ libs. I read other topics I need to add -lws2_32 to gcc command, but I've CLion and I don't know how to fix it.

Console:

CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&, unsigned char, unsigned char)':
C:/MinGW/include/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `__imp_WSAStartup'
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&)':
C:/MinGW/include/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `__imp_WSACleanup'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\WsServer.dir\build.make:99: WsServer.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:67: CMakeFiles/WsServer.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:79: CMakeFiles/WsServer.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: WsServer] Error 2

What I should do?


回答1:


You can pass ws2_32 via target_link_libraries in your CMakeLists.txt, e.g.:

if(MINGW)
  target_link_libraries(YourTargetName ws2_32)
endif()


来源:https://stackoverflow.com/questions/38767653/how-to-fix-undefined-reference-to-imp-wsacleanup-boost-asio-in-clion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!