如何修复 CLion 中对 `GetAcceptExSockaddrs' (Boost.Asio) 的未定义引用
How to fix undefined reference to `GetAcceptExSockaddrs' (Boost.Asio) in CLion
我已经包含了 Boost 1.61.0。我的 C++ 项目有 , I added target_link_libraries(WsServer ws2_32)
and fixed it. Then, another error appeared. The code: WebSocket++ examples: simple_broadcast_server.cpp 。我该如何解决?
控制台:
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::socket_ops::complete_iocp_accept(unsigned long long, void*, unsigned long, sockaddr*, unsigned long long*, unsigned long long, boost::system::error_code&)':
C:/MinGW/include/boost/asio/detail/impl/socket_ops.ipp:199: undefined reference to `GetAcceptExSockaddrs'
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::win_iocp_socket_service_base::start_accept_op(boost::asio::detail::win_iocp_socket_service_base::base_implementation_type&, bool, boost::asio::detail::socket_holder&, int, int, int, void*, unsigned long, boost::asio::detail::win_iocp_operation*)':
C:/MinGW/include/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:495: undefined reference to `AcceptEx'
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::win_iocp_socket_service_base::restart_accept_op(unsigned long long, boost::asio::detail::socket_holder&, int, int, int, void*, unsigned long, boost::asio::detail::win_iocp_operation*)':
C:/MinGW/include/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:520: undefined reference to `AcceptEx'
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:
cmake_minimum_required(VERSION 3.5)
project(WsServer)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(SOURCE_FILES src/main.cpp)
include_directories(C:/Users/Marczak/CPPLibs)
find_package(Boost REQUIRED COMPONENTS filesystem)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(WsServer ${SOURCE_FILES})
target_link_libraries(WsServer ${Boost_LIBRARIES})
target_link_libraries(WsServer ws2_32)
看来您必须将 wsock32
添加到 link 库,请参阅 this post。
我已经包含了 Boost 1.61.0。我的 C++ 项目有 target_link_libraries(WsServer ws2_32)
and fixed it. Then, another error appeared. The code: WebSocket++ examples: simple_broadcast_server.cpp 。我该如何解决?
控制台:
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::socket_ops::complete_iocp_accept(unsigned long long, void*, unsigned long, sockaddr*, unsigned long long*, unsigned long long, boost::system::error_code&)':
C:/MinGW/include/boost/asio/detail/impl/socket_ops.ipp:199: undefined reference to `GetAcceptExSockaddrs'
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::win_iocp_socket_service_base::start_accept_op(boost::asio::detail::win_iocp_socket_service_base::base_implementation_type&, bool, boost::asio::detail::socket_holder&, int, int, int, void*, unsigned long, boost::asio::detail::win_iocp_operation*)':
C:/MinGW/include/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:495: undefined reference to `AcceptEx'
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `boost::asio::detail::win_iocp_socket_service_base::restart_accept_op(unsigned long long, boost::asio::detail::socket_holder&, int, int, int, void*, unsigned long, boost::asio::detail::win_iocp_operation*)':
C:/MinGW/include/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:520: undefined reference to `AcceptEx'
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:
cmake_minimum_required(VERSION 3.5)
project(WsServer)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(SOURCE_FILES src/main.cpp)
include_directories(C:/Users/Marczak/CPPLibs)
find_package(Boost REQUIRED COMPONENTS filesystem)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(WsServer ${SOURCE_FILES})
target_link_libraries(WsServer ${Boost_LIBRARIES})
target_link_libraries(WsServer ws2_32)
看来您必须将 wsock32
添加到 link 库,请参阅 this post。