如何在CLion中修复对`__imp_WSACleanup'(Boost.Asio)的未定义引用 [英] How to fix undefined reference to `__imp_WSACleanup' (Boost.Asio) in CLion

查看:672
本文介绍了如何在CLion中修复对`__imp_WSACleanup'(Boost.Asio)的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C ++项目包括 Boost

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.

控制台:

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

我该怎么办?

推荐答案

您可以通过CMakeLists.txt中的target_link_libraries通过ws2_32,例如:

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

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

这篇关于如何在CLion中修复对`__imp_WSACleanup'(Boost.Asio)的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆