How to fix undefined reference to `GetAcceptExSockaddrs' (Boost.Asio) in CLion
<p>I have included Boost 1.61.0. My C++ project had <a href="https://stackoverflow.com/questions/38767653/how-to-fix-undefined-reference-to-imp-wsacleanup-boost-asio-in-clion">similar problem</a>, I added <code>target_link_libraries(WsServer ws2_32)</code> and fixed it. Then, another error appeared. The code: <a href="https://github.com/zaphoyd/websocketpp/blob/master/examples/simple_broadcast_server/simple_broadcast_server.cpp" rel="nofollow noreferrer">WebSocket++ examples: simple_broadcast_server.cpp</a> . How I can fix it?</p>

<p>Console:</p>

<pre><code>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&amp;)':
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&amp;, bool, boost::asio::detail::socket_holder&amp;, 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&amp;, 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
</code></pre>

<p>CMakeLists.txt:</p>

<pre><code>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)
</code></pre>