gpt4 book ai didi

c++ - 如何修复 CLion 中对 `__imp_WSACleanup' (Boost.Asio) 的 undefined reference

转载 作者:搜寻专家 更新时间:2023-10-31 01:34:43 28 4
gpt4 key购买 nike

我的 C++ 项目包括 BoostWebSocket++库。我阅读了其他主题,我需要将 -lws2_32 添加到 gcc 命令,但我有 CLion,但我不知道如何修复它。

控制台:

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,例如:

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

关于c++ - 如何修复 CLion 中对 `__imp_WSACleanup' (Boost.Asio) 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38767653/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com